jeudi 26 février 2015

How to uncheck the checkbox within the grid view template field?

I have two check boxes with the GridView TemplateField. I want to uncheck the checked boxes after submission. My gridview



<asp:GridView ID="GridView1" runat="server" HorizontalAlign="Center" DataKeyNames="ShiftID"
Width="177px" onrowdatabound="GridView1_RowDataBound1">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="ChbGrid" runat="server"
oncheckedchanged="ChbGrid_CheckedChanged" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="ChbGridHead" runat="server" AutoPostBack="True"
Font-Bold="True" oncheckedchanged="ChbGridHead_CheckedChanged" />
</HeaderTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


I tried in below mentioned methode



public void checkboxclear()
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox chkrow = (CheckBox)row.FindControl("ChbGrid");
if(chkrow.Checked==true)
{
chkrow.Checked = false;//it works
}
else
{
CheckBox chkrow1 = (CheckBox)row.FindControl("ChbGridHead");
if (chkrow1.Checked == true)
{
chkrow1.Checked = false;//it shows error like "Object reference not set to instance of an object"
}
}
}


How can I improve my code to solve this issue? Why I am unable to call these check boxes inside the aspx.cs page





Aucun commentaire:

Enregistrer un commentaire