Setting a DataBound items Visibility to false?
I have a 开发者_开发问答GridView with a load of data in, there is an ID associated to the data that I would not like to be visible to the users. All worked fine when all the cells were visible, but as soon as I change the ID DataBound column to false, when I try to access the item in code I get "" instead of it's actual value (that worked perfectly when it was visible).
Is there a reason for this? If not, how should I be approaching this?
Thanks in advance,
Lloyd
For some reason, the data in hidden columns are not preserved unless the column is visible when binding to the grid. Try something like the following:
myGrid.Columns(0).Visible = True
myGrid.DataSource = myDataSource
myGrid.DataBind()
myGrid.Columns(0).Visible = False
Now your column isn't visible, but it contains your ids.
Not sure why its happening but one solution is to move the value into a hidden field.
精彩评论