To sum up the hidden columns in the Gridview, two methods are described below:
This means that the column in the data Table you get will not bind a value to it, and make sure that your Table contains this column of data. For example, you need to query two columns: name; id, now you only want to display the name, not the id, but when the background code needs to use the id value, you can directly query it and bind the name to a column on the Gridview, set the DataKeyName = "id" of the Gridview, and then directly set the value in the background, for example, to obtain the id value of the first line, you can directly GridView1.DataKeys [1] ["id,
Method 2:
Directly write in the GridView1_RowCreated event: if (e. Row. RowType = DataControlRowType. DataRow |
E. Row. RowType = DataControlRowType. Header)
{
E. Row. Cells [0]. Visible = false; // If id is the first column, set its visibility to false,
}
When the value is set, e. Row. Cells [0] is enough.