Click here to Skip to main content
15,889,482 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one asp check box in Datagrid Header Template while clicking the search button it should bind the value from database. how can i do this.
Posted

Hi , Hope it help you

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
 
as per my understanding you want to bind the checkbox in the header of the gridview.
1)add the checkbox (HTML preferred) to the gridview headertemplate.
2)handle the rowdatabound event of the gridview.
3)find the checkbox in above event.
4)bind the data accordingly to it.

correct if I am wrong....
 
Share this answer
 

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