如何隐藏gridview中的列如果是自动生成的...

问题描述:

我也试过编码为

I had also tried the coding as

GridView1.Columns[0].Visible = false



但是不工作......

第一列是我需要隐藏的id字段..但不应该删除它...


But not working...
the first column is an "id" field i need to hide.. but should not remove it...

为了您的目的,您应该使用 DataKeyNames [ ^ ]

简而言之,将gridview的DataKeyNames属性设置为id字段。在数据绑定期间,GridView将查找名为id的字段,并将其用作GridView中每行的主键。这样,您不必显示ID,但仍然可以检索它。
For your purpose, you should be using DataKeyNames[^]
Briefly, set the DataKeyNames property of the gridview to the id field. During databinding, the GridView will look for a field named id and used it the primary key for each row in the GridView. This way, you do not have to display the id yet still being able to retrieve it.