Check box in grid returns false [Resolved]

Posted by sourabhghosh49-13964 under ASP.NET on 3/27/2012 | Points: 10 | Views : 1549 | Status : [Member] | Replies : 3
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=.;initial catalog=aaa;uid=sa;password=*****");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from Registration", con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();

}
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row =GridView1.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;

if (isChecked)
{
string xSideID = GridView1.Rows[i].Cells[1].Text;

}
}
}






html==
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"><Columns>
<asp:TemplateField HeaderText="Select">
<ItemStyle HorizontalAlign="Center" Width="5%" />
<HeaderStyle width="5%" HorizontalAlign="Center"/>
<ItemTemplate >
<asp:CheckBox Enabled="true" ID="chkSelect" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Rid" HeaderText="Rid" />
<asp:BoundField DataField="Name" HeaderText="Name" />
</Columns>
</asp:GridView>




when i check the checkboxes and press the button it returns false at-- bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;
for any index.

please tell me where i m wrong.......

sourabh


Responses

Posted by: Balajikcp8 on: 3/27/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Pls try to bind gridview inside this condition

if (!Page.IsPostBack){ }


sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: sourabhghosh49-13964 on: 3/27/2012 [Member] Starter | Points: 25

Up
0
Down
A very thanks to u Mr. Balaji

sourabh

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Balajikcp8 on: 3/27/2012 [Member] Starter | Points: 25

Up
0
Down
Welcome

sourabhghosh49-13964, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response