简体   繁体   English

如何将复选框列添加到gridview

[英]how to add checkbox column to gridview

How to add checkbox column to gridview . 如何将复选框列添加到gridview。

i've tried: 我试过了:

foreach (GridViewRow objRow in GridView1.Rows)
{
   TableCell tcCheckCell = new TableCell();
   CheckBox chkCheckBox = new CheckBox();
   tcCheckCell.Controls.Add(chkCheckBox);

   objRow.Cells.Add( tcCheckCell);
}

How can i add the objrow to gridview? 如何将objrow添加到gridview? Or is there any other method of adding a checkbox column to an ASP.net GridView ? 或者是否有任何其他方法将复选框列添加到ASP.net GridView

The problem is that you cannot add a CheckBox field to a GridView in order to have a column of checkboxes - the GridView doesn't support it: 问题是你不能将一个CheckBox字段添加到GridView以便有一列复选框 - GridView不支持它:

Instead you have to change the template of each row, manually adding a CheckBox control to the template of a row. 相反,您必须更改每行的模板 ,手动将CheckBox控件添加到行的模板。

  • i can't tell you how to do that 我无法告诉你如何做到这一点
  • i can't tell you how to read which items the user has checked 我无法告诉您如何阅读用户已检查的项目
  • i can't tell you how to default some of them to checked 我不能告诉你如何默认一些它们来检查

But it's what you have to do. 但这就是你必须要做的。

是一个如何做到一点的好例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM