我遇到嵌套转发器问题。我用了两个中继器。 Rpt1和rpt2。我在rpt1_ItemDataBound中使用了rpt1ID来从dbo.rpt_2中检索数据。我得到了那个输出。
<form method="post" action="Default2.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTAwOTY3Njk1OQ9kFgICAw9kFgICAQ8WAh4LXyFJdGVtQ291bnQCAxYGZg9kFgRmDxUBBXdoaXRlZAIDDxYCHwACARYCZg9kFgJmDxUBCXdoaXRlIGNhcmQCAQ9kFgRmDxUBBWJsYWNrZAIDDxYCHwACARYCZg9kFgJmDxUBCWJsYWNrIGNhdGQCAg9kFgRmDxUBBnllbGxvd2QCAw8WAh8AAgEWAmYPZBYCZg8VAQ15ZWxsb3cgZmxvd2VyZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAwUccnB0MSRjdGwwMCRycHQyJGN0bDAwJGNiVGVzdAUccnB0MSRjdGwwMSRycHQyJGN0bDAwJGNiVGVzdAUccnB0MSRjdGwwMiRycHQyJGN0bDAwJGNiVGVzdFtBgK000gWzwpdFcFINp56BH3iEbpu32p0ucdmVkKqQ">
</div>
<div class="aspNetHidden">
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAtOAOd9ybgP4HtwI1kjAG/MIN3G+dZU3QaatNlxgtD/xtMq/m65MPpIiFULd6envm8Yw3LjELwW1svU+QRcZXObI4OhWhKb5ze/nlyzwgtKpgcaK/fYMlrAwV8ml1fRddm1Nj+RQVgfhH19Mqy7JakoOGJJxEuYbMh7gt3d2UEgxjVWyspxiwdSrYPfy2ovFed8sdKhZF2WzHs512/4sp8RUbCI4mLLhd/eyEmnxetg1jh3iXH1t2bNB/y0oxlp17XcDdrSIJMmEc3BKiLo+WAV">
</div>
rpt1 white<br>
<input type="hidden" name="rpt1$ctl00$hfRpt1ID" id="rpt1_hfRpt1ID_0" value="1">
---rpt2 white car <input id="rpt1_rpt2_0_cbTest_0" type="checkbox" name="rpt1$ctl00$rpt2$ctl00$cbTest" checked="checked"><br>
<input type="hidden" name="rpt1$ctl00$rpt2$ctl00$hfCheckedCheckBoxes" id="rpt1_rpt2_0_hfCheckedCheckBoxes_0" value="1">
rpt1 black<br>
<input type="hidden" name="rpt1$ctl01$hfRpt1ID" id="rpt1_hfRpt1ID_1" value="2">
---rpt2 black cat <input id="rpt1_rpt2_1_cbTest_0" type="checkbox" name="rpt1$ctl01$rpt2$ctl00$cbTest" checked="checked"><br>
<input type="hidden" name="rpt1$ctl01$rpt2$ctl00$hfCheckedCheckBoxes" id="rpt1_rpt2_1_hfCheckedCheckBoxes_0" value="2">
rpt1 yellow<br>
<input type="hidden" name="rpt1$ctl02$hfRpt1ID" id="rpt1_hfRpt1ID_2" value="3">
---rpt2 yellow flower <input id="rpt1_rpt2_2_cbTest_0" type="checkbox" name="rpt1$ctl02$rpt2$ctl00$cbTest" checked="checked"><br>
<input type="hidden" name="rpt1$ctl02$rpt2$ctl00$hfCheckedCheckBoxes" id="rpt1_rpt2_2_hfCheckedCheckBoxes_0" value="3">
<input type="submit" name="btnFindCheckBoxes" value="Get Checked Textboxes" id="btnFindCheckBoxes">
</form>
你无法看到但是每个rpt2行之后都有复选框。我的问题是,当我单击按钮时,如何获取已选中复选框的ID。我可以获得复选框的ID,但是当我点击一个按钮时,我找不到如何获取它们的方法。我的代码如下。我很感激每一个答案。如果我在这条消息中做错了什么,请不要生气。我是全新的,这是我的第一个消息。
<asp:Repeater ID="rpt1" runat="server" OnItemDataBound="rpt1_ItemDataBound">
<ItemTemplate>rpt1 <%#Eval("rptName").ToString() %><br />
<asp:HiddenField ID="hfRpt1ID" runat="server" Value='<%#Eval("rpt1ID").ToString() %>' />
<asp:Repeater ID="rpt2" runat="server" OnItemDataBound="rpt2_ItemDataBound">
<ItemTemplate>
---rpt2 <%#Eval("rpt2Text").ToString() %> <asp:CheckBox ID="cbTest" runat="server" Checked="true"/><br />
<asp:HiddenField ID="hfCheckedCheckBoxes" runat="server" Value='<%#Eval("rpt1ID").ToString() %>' />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
<asp:Button ID="btnFindCheckBoxes" runat="server" OnClick="btnFindCheckBoxes_Click" Text="Get Checked Textboxes"/>
protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DataRowView row = (DataRowView)e.Item.DataItem;
boolArray();
Repeater nestedRepeater = e.Item.FindControl("rpt2") as Repeater;
d.Parameters.AddWithValue("rpt1Id", row["rpt1ID"]);
nestedRepeater.DataSource = d.GetDataTable("Select * from rpt_2 where rpt1ID=@rpt1Id");
nestedRepeater.DataBind();
}
protected void rpt2_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DataRowView row = (DataRowView)e.Item.DataItem;
int a = Convert.ToInt32(row["rpt2ID"]);
CheckBox ch = e.Item.FindControl("cbTest") as CheckBox;
if (ch.Checked)
{
findCheckboxes(a);
}
}
private void findCheckboxes(int a)
{
xxxxx.Add(a);
Response.Write(a + " cliecked-");
}