<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:TextBox ID="txtAvailableID" runat="server" text='<%#Eval("AvailableID") %>' ></asp:TextBox>
<asp:TextBox ID="txtSchedule" runat="server" text=' <%#Eval("ScheduleID") %>'></asp:TextBox>
<%#Eval("Venue") %>
<%#Eval("startTime").ToString() %>-<%#Eval("endtime") %><asp:CheckBox Checked="false" ID="cbschedule" runat="server" /><br />
</ItemTemplate>
</asp:Repeater>
在背后的代码中
protected void Button2_Click(object sender, EventArgs e)
{
int countchecked = 0;
for (int item = 0; item < Repeater1.Items.Count; item++)
{
CheckBox box = Repeater1.Items[item].FindControl("cbschedule") as CheckBox;
TextBox txtAvailableID = Repeater1.Items[item].FindControl("txtAvailableID") as TextBox;
TextBox txtSchedule = Repeater1.Items[item].FindControl("txtSchedule") as TextBox;
if (box.Checked)
{
countchecked++;
TblEnrollDetail.Rows[item].Cells[0].Text = txtSchedule.Text.ToString();
TblEnrollDetail.Rows[item].Cells[1].Text = txtAvailableID.Text.ToString();
}
else
{
String myStringVariable = "Do not choose more than 1";
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
}
}
}