<asp:GridView ID="science_tab" runat="server" AutoGenerateColumns="false" ShowHeader="false" class="subjects_tab">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="sciencefees_check" runat="server" Text='<%# bind("sub_name") %>' ></asp:CheckBox><%-- i tried binding the text to custom name like Text="anyname" --%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<label class="rsperhr" for="sciencefees_text">Rupees</label>
<asp:TextBox ID="sciencefees_text" runat="server" Width="40px" ></asp:TextBox>
<label class="rsperhr" for="sciencefees_text">Per Hour</label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and a label and button..
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
this is the on button onclick event:
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < science_tab.Rows.Count; i++)
{
GridViewRow row = science_tab.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("sciencefees_check")).Checked;
if (isChecked)
{
Label1.Text += i + " checked ";
}
else
Label1.Text += i + " unchecked ";
}
}
does not matter how many checkboxes i check if statement always goes for false... label1.Text gives the result 0 unchecked 1 unchecked 2 unchecked ...