如何在 gridview 的页眉模板中设置复选框值?公司#侧

how can i set checkbox value in header template in gridview? inc# side

我想在 cs 代码而不是 asp.net 侧的网格视图中用 reader 值更改复选框值?我该如何设置它? "headerCell.FindControl("c") as CheckBox = true" 它不起作用

我试过了

    while (reader.Read())
    {
        foreach (TableCell headerCell in GridView1.HeaderRow.Cells)
        {
            if (reader["isSelected"].ToString().Equals("true"))
            {
                headerCell.FindControl("c") as CheckBox = true;
            }               
        }
    }

如果您可以通过这种方式在 header 中找到您的 CheckBox

CheckBox chk = (CheckBox)GridView1.HeaderRow.FindControl("c"); // change that ID to something more meaningful

你可以check/uncheck这样:

if(reader.Read())
    chk.Checked = reader.GetBoolean(reader.GetOrdinal("isSelected"));

试试这个

CheckBox ChkBoxRows = GridView1.HeaderRow.FindControl("c") as CheckBox;

然后你可以设置truefalse 属性到ChkBoxRows,反映到c

if(reader.Read())
   ChkBoxRows.Checked = reader.GetBoolean(reader.GetOrdinal("isSelected"));