views:

50

answers:

4

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

+3  A: 

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.

Jason Berkan
Thanks, I have looked into doing it that way. I couldn't quite get my head around it but I might have to get it another look.
flyersun
+2  A: 

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.

Dining Philanderer
+2  A: 

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.

Ed B
+1  A: 

Accessing GridView Invisible Columns

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

azamsharp