The gridview cannot hide the column visable = false like the DataGrid, so that the background cannot read the data of this hidden column. Today we have summarized two methods to solve this problem.
1. Use CSS
Add the following content to the CSS file:
. Hidden {display: none ;}
Then, in the column editing dialog box of the gridview, set the columns to be hidden and set the cssclass attribute of footstyle, headerstyle, and itemstyle to "hidden" respectively.
2. Use the properties of the gridview.
Although method 1 can be implemented, it seems that it is not a good method. In fact, it can be implemented by using the properties of the gridview itself, that is, the gridview has provided such a function.
First, set the datakeynames attribute (you can set multiple attributes) as follows:
<Asp: gridview id = "gridview1" runat = "server" datakeynames = "ID">
Then read, for example, the value of the ID of the row I to be read:
String id = gridviews1.datakeys [I] ["ID"]. tostring ();