如何进行Repeater嵌套Repeater
我想做一个商品类型的级联查询,及商品的大类型,小类型,具体商品(如:体育用品--篮球--双星篮球)...
我想做一个商品类型的级联查询,及商品的大类型,小类型,具体商品(如:体育用品--篮球--双星篮球)
展开
2个回答
2014-01-02
展开全部
假设存在“大商品”、“小商品”和“货物”两张表,小商品的BID是大商品的外键;货物的GID又是小商品的外键。那么: <asp:Repeater id="repBigGoods" DataKeys="xxx"....> <ItemTemplate> <%#Eval("BigCategoryName")%> <asp:Repeater id="repSmallgoods" ... DataSourceId="dsSmallGoods" DataKeys="xxx"> <ItemTemplate>
<%#Eval("SmallCategoryName")%> <asp:Repeater id="repGoods" ...> <ItemTemplate>
<%#Eval("GoodsName")%>
</ItemTemplate>
</asp:Repeater> <asp:SqlDataSource id="dsGoods" .... SelectCommand="select GoodsName from goods where gid=@gid"....>
<SelectParameter>
<asp:Parameter Name="gid" Type="Int32"..../>
</SelectParameter>
</ItemTemplate> </asp:Repeater> <asp:SqlDataSource id="dsSmallGoods" .... SelectCommand="select SmallCategoryName from smalllcategory where bid=@bid"....>
<SelectParameter>
<asp:Parameter Name="bid" Type="Int32"..../>
</SelectParameter> <ItemTemplate></asp:Repeater>然后:private void repBigGoods_ItemDataBound(object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
if( (item.ItemType == ListItemType.Item) ||
(item.ItemType == ListItemType.AlternatingItem) )
{
Repeater repsmallgoods = (Repeater) item.FindControl("repSmallgoods");
SqlDataSource dsSmallGoods = (SqlDataSource)repsmallgoods.FindControl("dsSmallGoods")as SqlDataSource;
dsSmallGoods.SelectParameters["bid"].DefaultValue = (e.Item As DataRowView).Row["Primary Column Name"].ToString();
}
}private void repSmallgoods_ItemDataBound(object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
if( (item.ItemType == ListItemType.Item) ||
(item.ItemType == ListItemType.AlternatingItem) )
{
Repeater repGoods = (Repeater) repsmallgoods.FindControl("repGoods");
SqlDataSource dsGoods = (SqlDataSource)repsmallgoods.FindControl("dsgoods")as SqlDataSource;
dsGoods.SelectParameters["gid"].DefaultValue = (e.Item As DataRowView).Row["Primary Column Name"].ToString();
}
} 具体可以参考这里(双层嵌套):http://www.codeproject.com/KB/aspnet/AspNetNestedRepeaters.aspx
<%#Eval("SmallCategoryName")%> <asp:Repeater id="repGoods" ...> <ItemTemplate>
<%#Eval("GoodsName")%>
</ItemTemplate>
</asp:Repeater> <asp:SqlDataSource id="dsGoods" .... SelectCommand="select GoodsName from goods where gid=@gid"....>
<SelectParameter>
<asp:Parameter Name="gid" Type="Int32"..../>
</SelectParameter>
</ItemTemplate> </asp:Repeater> <asp:SqlDataSource id="dsSmallGoods" .... SelectCommand="select SmallCategoryName from smalllcategory where bid=@bid"....>
<SelectParameter>
<asp:Parameter Name="bid" Type="Int32"..../>
</SelectParameter> <ItemTemplate></asp:Repeater>然后:private void repBigGoods_ItemDataBound(object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
if( (item.ItemType == ListItemType.Item) ||
(item.ItemType == ListItemType.AlternatingItem) )
{
Repeater repsmallgoods = (Repeater) item.FindControl("repSmallgoods");
SqlDataSource dsSmallGoods = (SqlDataSource)repsmallgoods.FindControl("dsSmallGoods")as SqlDataSource;
dsSmallGoods.SelectParameters["bid"].DefaultValue = (e.Item As DataRowView).Row["Primary Column Name"].ToString();
}
}private void repSmallgoods_ItemDataBound(object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
if( (item.ItemType == ListItemType.Item) ||
(item.ItemType == ListItemType.AlternatingItem) )
{
Repeater repGoods = (Repeater) repsmallgoods.FindControl("repGoods");
SqlDataSource dsGoods = (SqlDataSource)repsmallgoods.FindControl("dsgoods")as SqlDataSource;
dsGoods.SelectParameters["gid"].DefaultValue = (e.Item As DataRowView).Row["Primary Column Name"].ToString();
}
} 具体可以参考这里(双层嵌套):http://www.codeproject.com/KB/aspnet/AspNetNestedRepeaters.aspx
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-01-02
展开全部
可以嵌套的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询