如何隐藏gridview中的列如果是自动生成的... [英] How to hide a column in gridview If it is auto generated...

查看:66
本文介绍了如何隐藏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.


这篇关于如何隐藏gridview中的列如果是自动生成的...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆