简体   繁体   中英

how to add checkbox column to gridview

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 ?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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