.NET v3.5
I have what seems to be some simple code that I've gotten to work before:
TableCell cell = new TableCell();
CheckBox c = new CheckBox();
c.AutoPostBack = true;
c.ID = string.Format( "cb_{0}", row.RowIndex ); // "row" is a GridViewRow
cell.Controls.Add( c );
row.Cells.AddAt( 0, cell );
The problem is the checkboxes aren't persisted between postbacks. But if I simply call the method on every postback, it prepends a new blank column to the front of the grid every time which pushes the data in the rows to the right for every postback. It's weird; each row will have the same number of cells and not change. It's just that the data gets "shifted" to the right. So data that was in cell[1]
will appear in cell[2]
after a postback. Then in cell[3] after the next postback. Etc.
What's up with this? Please remember this data is unbounded. The grid itself is not templatized but is being created on the fly from code. I simply need a way to check rows selected by the user.