码迷,mamicode.com
首页 > 其他好文 > 详细

多个repeater嵌套使用

时间:2015-01-12 17:22:16      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:

<ul>
<asp:Repeater ID="bClass" runat="server" OnItemDataBound="bClassList">
<ItemTemplate>
<li>
<div><%#Eval("x_classname") %></div>

<asp:Repeater ID="bsClass" runat="server" OnItemDataBound="bsClassList">
<HeaderTemplate><ul></HeaderTemplate>
<FooterTemplate></ul></FooterTemplate>
<ItemTemplate>
<li>
<div><%#Eval("x_classname") %></div>

<asp:Repeater ID="sClass" runat="server">
<HeaderTemplate><ul></HeaderTemplate>
<FooterTemplate></ul></FooterTemplate>
<ItemTemplate>
<li>
<div><%#Eval("x_classname") %></div>
</li>
</ItemTemplate>
</asp:Repeater>

</li>
</ItemTemplate>
</asp:Repeater>

</li>
</ItemTemplate>
</asp:Repeater>
</ul>

CS:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["login"] == null)
{
Response.Redirect("login.aspx");
Response.End();
}

OleDbConnection conn = dbopen.getDB();

string bStr = "select id,x_classname,taxis,preid from Table where preid=0 order by taxis asc,id asc";
OleDbDataAdapter rs = new OleDbDataAdapter(bStr,conn);
conn.Open();
DataSet rd = new DataSet();
rs.Fill(rd);
bClass.DataSource = rd;
bClass.DataBind();
conn.Close();
}

protected void bClassList(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string preid = ((DataRowView)e.Item.DataItem).Row["id"].ToString();//获得对应ID
Repeater bsClass = (Repeater)e.Item.FindControl("bsClass");//找到要绑定数据的Repeater
if (bsClass != null)
{
OleDbConnection sc = dbopen.getDB();
string ssql = "select id,x_classname,taxis,preid from Table where preid="+preid+" order by taxis asc,id asc";

OleDbDataAdapter srs = new OleDbDataAdapter(ssql,sc);
sc.Open();
DataSet srd = new DataSet();
srs.Fill(srd);

bsClass.DataSource = srd;
bsClass.DataBind();
sc.Close();
}
}
}
protected void bsClassList(object sender,RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{

string preid = ((DataRowView)e.Item.DataItem).Row["id"].ToString();//获得对应ID

Repeater sClass = (Repeater)e.Item.FindControl("sClass");//找到要绑定数据的Repeater
if (sClass != null)
{
OleDbConnection sc = dbopen.getDB();
string ssql = "select id,x_classname,taxis,preid from Table where preid=" + preid + " order by taxis asc,id asc";

OleDbDataAdapter srs = new OleDbDataAdapter(ssql, sc);
sc.Open();
DataSet srd = new DataSet();
srs.Fill(srd);

sClass.DataSource = srd;
sClass.DataBind();
sc.Close();
}

}
}

 

多个repeater嵌套使用

标签:

原文地址:http://www.cnblogs.com/hcf-0320/p/4218647.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!