Insert checkbox column at the end of gridview

My GridView contains 20 columns that are added programmatically (DataTable, DataColumn, DataRow and DataSet). Now I need to insert the checkbox column as the last column (21 st ). How to add it?

I tried to add using the regular template field (from the design tab) in the .aspx file, but it adds a checkbox as the first column and not as the last.

+4
source share
2 answers

If you are binding your GridView using a DataTable , do this before setting the GridView DataSource .

 dataTable.Columns.Add("Select", Type.GetType("System.Boolean")); DemoGrid.DataSource = dataTable; DemoGrid.DataBind(); foreach (GridViewRow row in DemoGrid.Rows) { //check box is the first control on the last cell. CheckBox check = row.Cells[row.Cells.Count - 1].Controls[0] as CheckBox; check.Enabled = true; } 

Regarding the unrelated side, note that your asp:GridView actually auto-generated.

+2
source

Create a TemplateField for the column with validation and check the box below as a footertemplate and enable the display of the footer via GridView.ShowFooter = true; The footer is a great place to place commonly available controls like this one.

The general trick, if the footer is not an option, is to associate an empty data row with a user interface that will have a checkbox.

NTN.

0
source

All Articles