如何将值绑定到Datagrid中的标题模板复选框 [英] How to Bind value to Header Template checkbox in Datagrid

查看:84
本文介绍了如何将值绑定到Datagrid中的标题模板复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Datagrid标头模板中有一个asp复选框,同时单击搜索按钮,它应该绑定数据库中的值.我该怎么做.

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.

推荐答案

希望对您有帮助

Hi , Hope it help you

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: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>


据我所知,您希望将gridview标题中的复选框绑定.
1)将复选框(首选HTML)添加到gridview标头模板.
2)处理gridview的rowdatabound事件.
3)在上述事件中找到该复选框.
4)将数据相应地绑定到它.

如果我错了,那就对了....
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....


这篇关于如何将值绑定到Datagrid中的标题模板复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆