ASP .Net 2.0 Update a record in data grid without displaying the ID field

Soldato
Joined
31 May 2006
Posts
4,239
Location
127.0.0.1
Hi all

Using VS2005 to create a VB .Net ASP .Net page. I have a grid view with a datasource which has an update query of:

Code:
update mytable set firstname=@firstname where id=@id

I dont want to display the field 'id' to the user. But when I hide it the update doesn't work. Is it possible to hide the 'id' field and still keep the update functionality?

Thanks in advance
 
Had the exact same problem last week :)

Whether or not there's a more better way of doing it I don't know, but in the end I just set that column to a specific class and had the class display set to none.

Still worked.

But I agree, there should be a more elegant way of doing it.
 
Sorry, yeah that's what I meant, just set the "ControlStyle-CSSClass" to a class which has it's Display set to nothing and it works.
 
OK, here you are:

In my styles.css I've a simple entry:

.hideDGColumn
{
display:none;
}

and on the datagrid itself I have the following that I want hidden

<asp:BoundField DataField="uid" HeaderText="uid" InsertVisible="False" ControlStyle-CssClass="hideDGColumn" FooterStyle-CssClass="hideDGColumn" HeaderStyle-CssClass="hideDGColumn" ItemStyle-CssClass="hideDGColumn"
ReadOnly="True" ShowHeader="false" SortExpression="uid" ControlStyle-Width="0px" >

Works perfectly. :)



*edit*

Did do a search for this last week on Google, and there was a fair amount of people asking the same thing. The most common answer was to set the columns Visible to False, but that has never worked for me at all.
 
Last edited:
Visible wont work (iirc) as that literally means the row isn't rendered so you can't look up the value from the cell....
 
another alternative that I used before I found out about datakeys is make all columns visible so they are populated and then hide the ones you don't want the user to see in code.

But using datakeys is the better way to go as you can have multiple keys for each row.
 
Back
Top Bottom