DATAGRID WITH HIDDEN ID COLUMN?

M

me

I have a column in my datagrid showing the
unique identifier of the rows from the database.
I want to hide it but if I switch "visible" off in
visual studios property builder for datagrids then
the column is removed completely. I still need to
access the ID programmably on Update events (its
an editable datagrid). How do I achieve that?
 
R

Rutger Smit

me said:
I have a column in my datagrid showing the
unique identifier of the rows from the database.
I want to hide it but if I switch "visible" off in
visual studios property builder for datagrids then
the column is removed completely. I still need to
access the ID programmably on Update events (its
an editable datagrid). How do I achieve that?


Check out the lovely DataGridGirl.com and go to articles, there you'll
find http://www.aspalliance.com/aldotnet/examples/hidecolumnarticle.aspx

//Rutger
 
P

Prodip Saha

You can't hide the asp control. If you set the visible property of an asp
control, you would have nothing rendered on the client. Generic Html control
is the solution--

If are trying to hide a column in a grid, use something like this in the
grid's column template:
<input type="hidden" runat="server" id="DatabaseFieldName or whatever"
value='<%# DataBinder.Eval(Container.DataItem, "DatabaseFieldName") %>'>

How to get the value at runtime?
HtmlInputHidden hinputDatabaseFieldName
=((HtmlInputHidden)e.Item.FindControl("DatabaseFieldName"));
//e=DataGridCommandEventArgs
long aLongValue=Int64.Parse(hinputDatabaseFieldName.Value); //you might
check hinputDatabaseFieldName against null in case the column does not
exist.

Hope this help.
Prodip
 
P

PL

You don't need to show the ID column, just set the DataKeyField property
of the datagrid to your ID field, i.e:

<asp:datagrid id="mygrid" DataKeyField="ID">
</asp:datagrid>

Then in your code use the DataKeys array when editing,
for example:

id = mygrid.DataKeys[mygrid.EditItemIndex];

PL.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top