在网格视图中,单击标题中的复选框时,选择/取消选中列中的所有复选框

时间:2017-08-03 13:40:51

标签: javascript c# asp.net

  

当我点击标题中的复选框时,它应该选择中的所有复选框        那一栏。我没有使用项目模板和标题模板        复选框。

protected void gv_ProjectResourceDatasetAccess_RowDataBound(object 
sender, GridViewRowEventArgs e)
{
    //DataRowView drview = e.Row.DataItem as DataRowView;
    if (e.Row.RowType == DataControlRowType.Header)
    {
        for (int i = 0; i < e.Row.Cells.Count; i++)
        {
                CheckBox chk = new CheckBox();
                chk.Text = e.Row.Cells[i].Text;
                e.Row.Cells[i].Controls.Add(chk);
                e.Row.Cells[i].Attributes.Add("OnClick", "return 
SelectAll(this)");
        }

    }

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        int i = 0;
        foreach (DataColumn col in ds_DatasetAccess.Tables[0].Columns) {
            CheckBox cb = new CheckBox();
            // cb.id = ... and other control setup
            // add your control here:
            e.Row.Cells[i].Controls.Add(cb);
            i++;
        }
    }
 }

 <asp:GridView id="gv_ProjectResourceDatasetAccess" runat="server"  
OnRowDataBound="gv_ProjectResourceDatasetAccess_RowDataBound"  
CssClass="table datatable-basic table-striped table-hover dataTable no-
footer"></asp:GridView>

0 个答案:

没有答案
相关问题