<asp:GridView ID="gvAppointments" runat="server" AutoGenerateColumns="False" DataKeyNames="IGSaleID,AppointmentPostcode" DataSourceID="dsAppointmentsbyDate">
<Columns>
<asp:BoundField DataField="IGSaleID" HeaderText="IGSaleID" InsertVisible="False" ReadOnly="True" SortExpression="IGSaleID" />
<asp:BoundField DataField="SaleID" HeaderText="SaleID" SortExpression="SaleID" />
<asp:BoundField DataField="DateAdded" HeaderText="DateAdded" SortExpression="DateAdded" />
<asp:BoundField DataField="AppointmentStartTime" HeaderText="AppointmentStartTime" SortExpression="AppointmentStartTime" />
<asp:BoundField DataField="AppointmentEndTime" HeaderText="AppointmentEndTime" SortExpression="AppointmentEndTime" />
<asp:BoundField DataField="HomePostCode" HeaderText="HomePostCode" SortExpression="HomePostCode" />
<asp:BoundField DataField="AppointmentPostcode" HeaderText="AppointmentPostcode" SortExpression="AppointmentPostcode" />
<asp:BoundField DataField="AppointmentSubject" HeaderText="AppointmentSubject" SortExpression="AppointmentSubject" />
<asp:TemplateField HeaderText="Compare Distance">
<ItemTemplate>
<asp:CheckBox ID="ckPostcode" runat="server" OnCheckedChanged="ckPostcode_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void ckPostcode_CheckedChanged(object sender, EventArgs e)
{
List<String> selection = new List<string>();
int checkedCnt = 0;
foreach (GridViewRow row in gvAppointments.Rows)
{
CheckBox chk = (CheckBox)row.FindControl("ckPostcode");
if (chk.Checked)
{
//put IGSaleID into selection
selection.Add(row.Cells[0].Text);
checkedCnt++;
}
}
if (checkedCnt > 2)
{
Response.Write("Please select only 2 items");
}
else if (checkedCnt <=1)
{
Response.Write("Please select items for comparison");
}
}
<asp:CheckBox ID="ckPostcode" runat="server" OnCheckedChanged="ckPostcode_CheckedChanged" />
<asp:CheckBox ID="ckPostcode" AutoPostBack="true" runat="server" OnCheckedChanged="ckPostcode_CheckedChanged" />
Protected Sub ckPostcode_CheckedChanged(sender As Object, e As EventArgs)
Dim selection As List(Of [String]) = New List(Of String)()
Dim checkedCnt As Integer = 0
For Each row As GridViewRow In gvAppointments.Rows
Dim chk As CheckBox = DirectCast(row.FindControl("ckPostcode"), CheckBox)
If chk.Checked Then
'put IGSaleID into selection
selection.Add(row.Cells(0).Text)
checkedCnt += 1
End If
If checkedCnt >= 2 Then
lbSelected.Text = "Too many items"
chk.Enabled = False
ElseIf checkedCnt <= 1 Then
lbSelected.Text = "the right amount"
chk.Enabled = True
End If
Next
End Sub
The only issue is that the checkboxes are disabled on only below the rows of the 2 ticked itemswell.... is that mean you want to disable other checkboxes after 2 items were checked?
IS there a way I can set the 1st checked box as an ' A' and the send as ' b'. The reason why I want to do this is that I want the first checkbox selected to go into textbox1 and the 2nd checkbox selected to go into textbox 2is that mean you want to show "A" (or 1st selected checkbox's value ??) into first text box? and later do the same to show "B" (or 2nd selected checkbox's value ??) into 2nd text box?