asp.net (C#): get value of a non-displayed field from a gridview selection -
I have a GridView control for an ObjectDataSource that gives a list of objects that looks like this:
public class X {public string DisplayName {get; } Public String Guide {get; }}
I do not want to show the Guid
property in GridView, but when an object is selected I need to recover it.
I can not get a "DataValueField" property, like for the ListBox control. For the solution, I try to get the cell text from visible = false
set and bound to the column Guid property, line
in the object SelectedIndexChanged < / Code> Method:
Protected Zero GridView1_SelectedIndexChanged (Object Sender, EventArgs e) {GridViewRow line = GridView1.SelectedRow; String id = row.Cells [2]. Text; // blank}
but this does not work - apparently if the column is not visible, its text property is left empty.
Only the DisplayName when I guid the selected object?
GridView1.DataKeyNames = New String [] {"Guid"}. After that, you can get the key by doing this: string GUID = GridView1.DataKeys [GridView1.SelectedRow.RowIndex];
Comments
Post a Comment