cs:
//repeater的databound事件
protected void RptBig_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//此处必须做判断,不然下面获取数据会报没有实例化或者为空
if (e.Item.ItemType== ListItemType.Item||e.Item.ItemType== ListItemType.AlternatingItem)
{
Repeater rptSmall= e.Item.FindControl("Rptsmall") as Repeater;//找到嵌套的控件
DataRowView ros= (DataRowView) e.Item.DataItem;//获得相关联的数据项
int id = Convert.ToInt32(ros["id"]);//获取对应行的Id
DataSet ds = Small(id);//自定义方法查询
rptSmall.DataSource = ds;
rptSmall.DataBind();
}
}
html:
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>大题型<input type="text" id="txtBig"/>
数量<input type="text" id="txtCount"/>
<input type="button" name="btnAdd" id="btnAdd" value="添加" />
</td>
</tr>
<asp:Repeater ID="RptBig" runat="server"
onitemdatabound="RptBig_ItemDataBound">
<ItemTemplate>
<tr>
<td><%# Container.ItemIndex+1 %></td>
<td><%# Eval("datixing") %> </td>
<td> 题数量<input type="text" name="name" id="Count" value="<%# Eval("dcount") %>" /></td>
</tr>
<tr>
<td>
<asp:Repeater ID="Rptsmall" runat="server">
<ItemTemplate>
<input type="checkbox" name="name" id="chk" />
<%# Eval("xiaotixing") %>
<input type="text" name="name" value="2" /><br />
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>