CheckBox is unchecked after Postback

Posted by Nandkishorre under ASP.NET on 8/6/2012 | Points: 10 | Views : 5614 | Status : [Member] | Replies : 1
Hi,
I am using check box in ItemTemplate(gridview) in User Control. I wrote some code in CheckedChanged event. It is Running. after completing the event my page is loading with uncheck checkbox.

<asp:TemplateField ItemStyle-Width="4%">
<ItemTemplate>
<asp:CheckBox Width="10%" ID="chkDocumentName" runat="server" onClick="GetGridViewSelectedRow();" OnCheckedChanged="chkDocumentName_CheckedChanged" AutoPostBack="true"/>
</ItemTemplate>
<ItemStyle Width="3%" />
</asp:TemplateField>



protected void chkDocumentName_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < gvDocumentTemplatestatus.Rows.Count; i++)
{
CheckBox chkbox = (CheckBox)gvDocumentTemplatestatus.Rows[i].FindControl("chkDocumentName");
if (chkbox.Checked == true)
{
Label lblTemplateId = (Label)gvDocumentTemplatestatus.Rows[i].FindControl("lblTempID");
Label lblDocumentNumberID = (Label)gvDocumentTemplatestatus.Rows[i].FindControl("lblDocumentNumberID");
Label lblTemplateName = (Label)gvDocumentTemplatestatus.Rows[i].FindControl("lblTemplateName");
Session["rownumber"] = i.ToString();
Session["TempID"] = lblTemplateId.Text;

}
else
{
if (Session["rownumber"] != null)
{
if (Convert.ToInt32(Session["rownumber"].ToString()) == i)
{
strcolumnnumber = "0";
Session["SubJobID"] = strcolumnnumber;
}
}
}
}
}

This is my code after postback my check box is unchecked.



if any one know about this tell me.

Regards
Nanda Kishore.CH .




Responses

Posted by: Sheonarayan on: 8/7/2012 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Not sure but have you kept GridView EnableViewState=false? If yes, this might be the reason.

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response