asp.net 关于循环嵌套显示

想问下ASP.NET中REAPTER能不能嵌套显示表格内容,也就是说REAPTER里能不能再嵌套一个REAPTER,如果不行的话,那我想实现循环嵌套怎么办,谢谢... 想问下ASP.NET中REAPTER能不能嵌套显示表格内容,也就是说REAPTER里能不能再嵌套一个REAPTER,如果不行的话,那我想实现循环嵌套怎么办,谢谢 展开
 我来答
招海散此牵1T
2006-04-05 · TA获得超过939个赞
知道小有建树答主
回答量:601
采纳率:0%
帮助的人:0
展开全部
可以的Reapter里面可以再嵌套,但里面的那个就不能直接使用数据绑定了。 会提示找不到控件。 这时里面的控件的数据绑定应该放在外面控件的ItemDataBound事件里面来绑定。

实例:
private void MainBorad_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater sb = (Repeater) e.Item.FindControl("SubBorad");

DataRowView rowv = (DataRowView)e.Item.DataItem;
//提取ID
int CatId = Convert.ToInt32(rowv["mID"]);
//根据分类ID查询该分类下的产品,并绑定子Repeater
sb.DataSource=......;
sb.DataBind();
}
}
百度网友2fb6b5f47
2006-04-05 · 超过19用户采纳过TA的回答
知道答主
回答量:75
采纳率:0%
帮助的人:70.3万
展开全部
REAPTER可以嵌套REAPTER。第一个REAPTER在代码中设置datasource,嵌套的REAPTER在页面设置datasource就可以实现嵌套了
举例:
后台:
private void Page_Load(object sender, System. EventArgs e)
{
// 在此处放置用户代码以初始化页面
SqlConnection con=DB.createConnection();
if (con.State==ConnectionState.Closed)
con.Open();
DataSet ds = new DataSet();
SqlDataAdapter sda1 = new SqlDataAdapter("select * from t_forum_board where boardlevel=1 and boardflag=1 order by boardid asc",con);
//Create and fill the DataSet.
sda1.Fill(ds,"forum_1");
//Create a second DataAdapter for the Titles table.
SqlDataAdapter sda2 = new SqlDataAdapter("select * from t_forum_board where boardlevel=2 and boardflag=1 order by boardid asc",con);
sda2.Fill(ds,"forum_2");
//Create the relation bewtween the Authors and Titles tables.
ds.Relations.Add("myrelation",ds.Tables["forum_1"].Columns["BoardId"],ds.Tables["forum_2"].Columns["ParentId"]);
//Bind the Authors table to the parent Repeater control, and call DataBind.
parent.DataSource = ds.Tables["forum_1"];
Page.DataBind();
//Close the connection.
con.Close();
}
页面上在进行嵌套的时候为第二个REAPTER设定DataSource
<asp:repeater id="child" DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>' runat="server">
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友aa08aae
2006-04-05
知道答主
回答量:94
采纳率:0%
帮助的人:35.5万
展开全部
REAPTER可以嵌套REAPTER。第一个REAPTER在代码中设置datasource,嵌套的REAPTER在页面设置datasource就可以实现嵌套了
举例:
后台:
private void Page_Load(object sender, System. EventArgs e)
{
// 在此处放置用户代码以初始化页面
SqlConnection con=DB.createConnection();
if (con.State==ConnectionState.Closed)
con.Open();
DataSet ds = new DataSet();
SqlDataAdapter sda1 = new SqlDataAdapter("select * from t_forum_board where boardlevel=1 and boardflag=1 order by boardid asc",con);
//Create and fill the DataSet.
sda1.Fill(ds,"forum_1");
//Create a second DataAdapter for the Titles table.
SqlDataAdapter sda2 = new SqlDataAdapter("select * from t_forum_board where boardlevel=2 and boardflag=1 order by boardid asc",con);
sda2.Fill(ds,"forum_2");
//Create the relation bewtween the Authors and Titles tables.
ds.Relations.Add("myrelation",ds.Tables["forum_1"].Columns["BoardId"],ds.Tables["forum_2"].Columns["ParentId"]);
//Bind the Authors table to the parent Repeater control, and call DataBind.
parent.DataSource = ds.Tables["forum_1"];
Page.DataBind();
//Close the connection.
con.Close();
}
页面上在进行嵌套的时候为第二个REAPTER设定DataSource
<asp:repeater id="child" DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>' runat="server">
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式