Datagrid won't post variables if hidden

  • Thread starter Thread starter Nick
  • Start date Start date
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
 
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; //


}
 
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.
 
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
 
Back
Top