我有一个listview“CategoriesList”,我在listview“CategoriesList”中有一个转发器“NewsRepeater”
<asp:ListView ID="CategoriesList" runat="server" DataKeyNames="CatID" DataSourceID="CategoriesListODS"
EnableModelValidation="True">
<EmptyDataTemplate>
No data was returned.
</EmptyDataTemplate>
<ItemSeparatorTemplate>
<div class="clear">
</div>
</ItemSeparatorTemplate>
<ItemTemplate>
<div class="head-Kuwait-University-news">
<h2>
<%# Eval("CatTitleAr")%>
</h2>
<asp:Literal ID="CatIDLtl" runat="server" Visible="false" Text='<%# Eval("CatID")%>' />
</div>
<!--End head Kuwait-University-newst-->
<asp:Repeater ID="NewsRepeater" runat="server" DataSourceID="NewsRepeaterODS">
<ItemTemplate>
<div class="content-Kuwait-University-news">
<div class="photo-Kuwait-University-news">
<a href="Items.aspx?ItemID=<%# Eval("ItemID")%>">
<img src="admin/ImageUpload/Items/<%# Eval("PictureID") %>.jpg" alt="" style="max-height: 141px;
max-width: 152px" />
</a>
</div>
<!--End photo-Kuwait-University-news-->
<div class="title-Kuwait-University-news">
<p>
<%# Eval("ItemTitleAr")%>
</p>
</div>
<!--End title-Kuwait-University-news-->
<div class="News-Kuwait-University-news">
<p>
<%# Eval("SDescriptionAr")%>
</p>
</div>
<!--End news-Kuwait-University-news-->
<div class="clear">
</div>
<div class="more-Kuwait-University-news">
<a href='Item.aspx?ItemID=<%# Eval("ItemID")%>'>
<img src="images/more.jpg" alt="" />
</a>
</div>
<!--End more-Kuwait-University-news-->
<div class="clear">
</div>
</div>
<!--Endcontent-Kuwait-University-news-->
<!--End category-->
</ItemTemplate>
</asp:Repeater>
<asp:ObjectDataSource ID="NewsRepeaterODS" runat="server" OldValuesParameterFormatString="{0}"
SelectMethod="Read" TypeName="Items">
<SelectParameters>
<asp:Parameter DefaultValue="3.5" Name="ActionCode" Type="String" />
<asp:Parameter Name="CatID" Type="Int64" DefaultValue='<%# Eval("CatID")%>' />
<%--<asp:ControlParameter ControlID="CategoriesList" Name="CatID" PropertyName="UniqueID" Type="Int64" />--%>
<asp:Parameter Name="ItemsID" Type="Int64" />
<asp:Parameter Name="Searchtext" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<!--End category-->
</ItemTemplate>
<LayoutTemplate>
<ul id="itemPlaceholderContainer" runat="server" style="">
<li runat="server" id="itemPlaceholder" />
</ul>
<div style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False"
ShowPreviousPageButton="False" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False"
ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
</asp:ListView>
<asp:ObjectDataSource ID="CategoriesListODS" runat="server" OldValuesParameterFormatString="{0}"
SelectMethod="Read" TypeName="Categories">
<SelectParameters>
<asp:Parameter DefaultValue="3" Name="ActionCode" Type="String" />
<asp:Parameter Name="CatID" Type="Int64" />
<asp:Parameter Name="Searchtext" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
如何从listview传递catID并将其作为ObjectDataSource中的SelectParameters“NewsRepeaterODS”?
感谢
答案 0 :(得分:0)
Protected Sub CategoriesList_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles CategoriesList.ItemDataBound
' Find the Inner DataSource control in this Row.
Dim NewsRepeaterODS As ObjectDataSource = DirectCast(e.Item.FindControl("NewsRepeaterODS"), ObjectDataSource)
' Set the SelectParameter for this DataSource control
' by re-evaluating the field that is to be passed.
Dim CatIDLtl As Literal = e.Item.FindControl("CatIDLtl")
NewsRepeaterODS.SelectParameters("CatID").DefaultValue = CatIDLtl.Text
End Sub