Click here to Skip to main content
15,888,157 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I put one asp.net checkbox in header template, when i click the save button i want to know the value(checked or not) of that checkbox. How can i get that checkbox value.
Posted

1 solution

Hi ,
i modified the solution
C#
protected void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Header)
    {

    }
}
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Header)
    {
        if (((CheckBox)e.Item.FindControl("CheckBox2")).Checked == true)
        {
            Response.Write("<script>alert('Checked')</script>");
        }
        else if (((CheckBox)e.Item.FindControl("CheckBox2")).Checked == false)
        {
            Response.Write("<script>alert('NOT Checked')</script>");

        }
    }
}

protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
    if (((CheckBox)sender).Checked == true)
    {
                 Response.Write("<script>alert('Checked')</script>");
    }
    else
    {
        Response.Write("<script>alert('NOT Checked')</script>");

    }
}


ASP.NET
<asp:DataGrid ID="DataGrid1" runat="server"
    DataSourceID="SqlDataSource1" onitemcreated="DataGrid1_ItemCreated"
          onitemdatabound="DataGrid1_ItemDataBound"  ClientIDMode="Static" >
          <Columns>
              <asp:TemplateColumn HeaderText="test">
                  <HeaderTemplate >
                      <asp:CheckBox ID="CheckBox2" runat="server" ClientIDMode="Static"
                          oncheckedchanged="CheckBox2_CheckedChanged" />

                  </HeaderTemplate>
              </asp:TemplateColumn>
          </Columns>
    </asp:DataGrid>
 
Share this answer
 
v2
Comments
Robymon 27-Mar-12 3:17am    
I want the solution for the Datagrid not the GridView, in Datagrid there is no property called HeaderRow.
Mohamed Mitwalli 28-Mar-12 4:40am    
hey , check this one .
faizyab 2009 27-Mar-12 4:01am    
This code is not working check again!!
Mohamed Mitwalli 28-Mar-12 4:40am    
check this one
Mohamed Mitwalli 27-Mar-12 4:02am    
could you share your code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900