<!--HTML代码端 -->
<!--测试Repeater绑定数据开始 -->
<!--最外层 Repeater嵌套-->
<asp:Repeater ID="rptList" runat="server">
<ItemTemplate>
<table class="pub_form" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<asp:HiddenField ID="hidId" Value='<%#Eval("字段名")%>' runat="server" />
</td>
</tr>
<!--第二层 Repeater嵌套-->
<asp:Repeater ID="rptListcheckdata" runat="server">
<ItemTemplate>
<tr>
<td colspan="4">
<p class="User_title" id="lbzizhi"><%# Eval("字段名") %></p>
</td>
</tr>
<!--第三层Repeater嵌套-->
<asp:Repeater ID="rptListchecked" runat="server">
<ItemTemplate>
<div id="content" class="content" style="display: none; color: red;">
<table border="0" cellspacing="0" cellpadding="0" class="pub_form">
<tr>
<td>
<asp:CheckBox ID="chckerror" runat="server" Text='<%# Eval("字段名") %>' />
</td>
</tr>
</div>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</table>
</ItemTemplate>
</asp:Repeater>
<!--测试Repeater绑定数据结束-->
<!--CS后台代码 -->
/// <summary>
/// 读取Repeater嵌套中第二层Repeater数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void rptList_ItemDataBound(object sender, RepeaterItemEventArgs e)//最外层Repeater事件
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rpColumnNews = (Repeater)e.Item.FindControl("rptListcheckdata");//找到里层(第二层)的repeater对象
//找到Repeater关联的数据项
DataRowView rowv = (DataRowView)e.Item.DataItem;
//提取关联ID
string strattachdic = Convert.ToString(rowv["atta_id"]);
string _strWhere = "ttach.atta_id =" + strattachdic + " and ID=" + Request.QueryString["id"].ToString();
string _orderby = " ttach.atta_id asc,zz_type desc ";
DataSet PurchasOrderDetail = bll.memberattachGetList2(_strWhere, _orderby);
rpColumnNews.DataSource = PurchasOrderDetail;
rpColumnNews.DataBind();
}
}
/// <summary>
/// 读取嵌套Repeater中第三层Repeater数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void rptListcheckdata_ItemDataBound(object sender, RepeaterItemEventArgs e)//第二层Repaater事件
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rpColumnNews = (Repeater)e.Item.FindControl("rptListchecked");//找到第三层的repeater对象
//找到Repeater关联的数据项
DataRowView rowv = (DataRowView)e.Item.DataItem;
//提取关联ID
string strattachdic = Convert.ToString(rowv["atta_id"]);
string _strWhere = "comment.atta_id =" + strattachdic + "";
string _orderby = " comment.atta_id asc,zz_type desc ";
DataSet PurchasOrderDetail = bll.memberattachGetList3(_strWhere, _orderby);
rpColumnNews.DataSource = PurchasOrderDetail;
rpColumnNews.DataBind();
}
}
//找到第三层的repeater对象中各个控件的值,其他各层控件查找与此类似
protected void RepeaterCheckbox()
{
Repeater repeater;
foreach (RepeaterItem item1 in rptList.Items)
{
repeater = (Repeater)item1.FindControl("rptListcheckdata");
if (repeater != null)
{
foreach (RepeaterItem item2 in repeater.Items)
{
repeater = (Repeater)item2.FindControl("rptListchecked");
if (repeater != null)
{
foreach (RepeaterItem item3 in repeater.Items)
{
CheckBox checkBox = (CheckBox)item3.FindControl("chckerror");
checkBox.Checked =true;
}
}
}
}
}
}
本文来自:记住你社区 转载请自觉注明作者地址,违者必究
详细代码请看原文,文章链接:http://www.jizhuni.com/forum.php?mod=viewthread&tid=24