我从数据库中选择数据并通过 asp:Repeater 绑定数据。我在 ItemTemplate 中创建复选框并从数据库接收数据。当我“选中”任何行上的复选框时,我想更新数据库中的数据。
protected void myRepeater_ItemDataBound(对象发送者,RepeaterItemEventArgs e){
//*** Level ID ***//
Label lblLevelID = (Label)(e.Item.FindControl("lblLevelID"));
if ((e.Item.FindControl("lblLevelID") != null))
{
lblLevelID.Text = DataBinder.Eval(e.Item.DataItem, "LevelID").ToString();
strLevelID = lblLevelID.Text;
//MyArr[Convert.ToInt16(In), 0] = strLevelID;
}
...
<asp:Repeater id="myRepeater" runat="server" OnItemDataBound="myRepeater_ItemDataBound">
<HeaderTemplate>
<table border="1" style="font-size:12px;" width="800">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="left" width="25"><asp:Label id="lblLevelID" runat="server"></asp:Label> </td>
<td align="left" width="350"><asp:Label id="lblLevelDesc" runat="server"></asp:Label> </td>
<td align="left" width="25"><asp:Label id="lblChoiceID" runat="server"></asp:Label> </td>
<td align="left" width="350"><asp:Label id="lblChoiceDesc" runat="server"></asp:Label> </td>
<td align="center" width="50"><%--<input type="checkbox" id="chkSelected" OnCheckedChanged="chkSelected_OnCheckedChanged" AutoPostBack="True" />--%>
<asp:CheckBox ID="chkSelected" runat="server" />
<asp:Label ID="lblTest" runat="server"></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>