Datagrid won't post variables if hidden

N

Nick

For some reason, why does ASP.net only see variables that are 'DISPLAYED'
inside a datagrid?

Even if the Field is Databound, I cannot post the variable or use it in an
updatecommand... it has to be visible??


I've tried putting the field on the page but making 'Visible = false' but it
still dosen't want to post or anything.


Is it a bug in Visual Web Developer 2005?


Cheers
 
S

sloan

I have a hidden (primary key) object in my GridView:

<asp:HiddenField ID="hidRemUUID" runat="server" Value='<%# Eval("MyUUID")
%>' />


Now, there is a more elegant way to keep track of the primary key... with a
GridView.



You might want to look into this also:
DataKeyNames="MyUUID" (this is declared in the <asp:GridView> element.



Then you can get to it like this:


protected void GridView1_SelectedIndexChanged(object sender, EventArgs
e)
{


GridView gv = (GridView)sender;

//string str0 = gv.DataKeyNames[0];

System.Guid uuid = (System.Guid)gv.DataKeys[gv.SelectedIndex].Value;

// or
//string uuid = (string)gv.DataKeys[gv.SelectedIndex].Value; //


}
 
E

Edwin Knoppert

I had a similar issue, i wanted to hide the autonumberfield.
Afaik i used a hidden div enclosing the item in a template.
If you really need to know, let me know, i have to look it up.
 
G

Guest

Hi Nick,

In DataGrid, you can apply invisible boundcolum to store data for using in
postback. However, in GridView invisible boundfield’s data cannot be
retrieved after postback. Good news is that you can use GridView.DataKeyNames
to speify multi-fields data then retrieve them by
GridView.DataKeys[row_indec].Values[col_index].

HTH

Elton Wang
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top