how to add checkbox column to gridview

落爺英雄遲暮 提交于 2019-12-20 04:12:29

问题


How to add checkbox column to 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? Or is there any other method of adding a checkbox column to an ASP.net GridView?


回答1:


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:

Instead you have to change the template of each row, manually adding a CheckBox control to the template of a row.

  • 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.




回答2:


Here is a good example of how to do it.



来源:https://stackoverflow.com/questions/3075044/how-to-add-checkbox-column-to-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!