开发者

Gridview making a column invisable

Hi I have a grid view which is dynamically generated via C# using a DataSet. I'm passing a row ID field (from the database) to the grid view, as this is required when a user clicks to edit a records. However I don't want the user to be able to view the column. I have tried the following but it doesn’t seem to work? Could anyone suggest a way to hide the column or a better way of attaching the information to the grid view row so it can be used at a later stage. c#

开发者_运维技巧
        DataColumn ColImplantCustomerDetailsID = new DataColumn();
        ColImplantCustomerDetailsID.ColumnName = "Implant ID";
        ColImplantCustomerDetailsID.DataType = typeof(int);
        ColImplantCustomerDetailsID.Visable = false; <-- visable doens't work here.

asp.net


DataColumn doesn't have a 'Visable' property. Heck, it doesn't have a 'Visible' property either.

Use this before you bind

gridviewNameHere.Columns[index].Visible = false;

You can make it visible again on one of your event handlers.


Another option, rather than hiding the column, is to use the DataKeyNames property of the GridView to store the name of the ID field. You can then use myGridView.SelectedValue to retrieve the selected ID.


Use the index of the column to hide it when you initialize it...

grid.Columns[index].Visible = false;

I actually hide a few things as you are suggesting, example - database status names for that row that can be used in code that the user does not need to see.


Accessing GridView Invisible Columns

http://www.highoncoding.com/Articles/178_Access_GridView_Invisible_Columns.aspx


In the OnRowDataBound event of the GridView component:

// c# 
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
    int index = 0; // put the index of the column you need hide.
    e.Row.Cells[index].Visible = false;  
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜