rachayita jaiswal

rachayita jaiswal

  • NA
  • 217
  • 106.2k

checkbox in gridview

Feb 19 2014 12:00 AM
Hi,
 
In my gridview i have put checkbox as checked but on  button click it is coming as false.
 
here is my code:
 
<asp:GridView ID="grdv_rights" runat="server" HorizontalAlign="Center" AllowPaging="true"
CellPadding="5" AutoGenerateColumns="false" Width="100%" PageSize="5" >
<FooterStyle ForeColor="Black" BorderColor="#3D98C1" />
<EmptyDataTemplate>
<asp:Label ID="lblEmptySearch" runat="server" Font-Bold="True" ForeColor="#0033CC">No Results Found....
</asp:Label>
</EmptyDataTemplate>
<Columns>
<asp:TemplateField HeaderText="Sl No" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50px" >
<ItemTemplate>
<%#Container.DataItemIndex+1%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-HorizontalAlign ="Center" DataField="Topic" HeaderText="Survey Topic" />
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle HorizontalAlign="center" />
<SelectedRowStyle BackColor="gray" ForeColor="Black" />
<PagerStyle Height="10px" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#2E90BD" Font-Names="calibri" Font-Size="11pt" ForeColor="White"
BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="center" />
<AlternatingRowStyle HorizontalAlign="center" />
</asp:GridView> 
 
<asp:Button ID="btn_rights_submit" runat="server" Text="Submit" OnClick="btn_rights_submit_Click" />&nbsp; 
------------------
 
protected void btn_rights_submit_Click(object sender, EventArgs e)
{
try
{
foreach (GridViewRow row in grdv_rights.Rows)
{
CheckBox chk = (CheckBox)row.FindControl("chkSelect");
if (chk.Checked)
{
lbl_user_rights.Text = "test";
}
}
}
catch(Exception ex)
{
obj_db.GetErrorFile("btn_rights_submit_Click", ex.Message);
}
 
please help..
 
 

Answers (7)