GridviewRow cell reference

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

Hi all,

I have a page that populates a gridview, the gridview has a select button
column enabled. When the users pushes the button to select a column

on the Gridview1_SelectedIndexChanged event I have

GridviewRow selectedRow = Gridview1.SelectedRow;

Session["SelectedEvent"] = selectedRow;

I do a page redirect and on the new page I want to fill a text box with one
of the cells in the GridviewRow.

So on the new pages onload event I have

GridviewRow selectedEventRow = (GridviewRow)Session["SelectedEvent"] ;

Now if I put:

txtBox1.Text = selectedEventRow.cells[4].Text;

the textbox populates fine with the info from cell index 4

What I would like to do is instead of using the cell index number I want to
reference it by the column name

something like
txtBox1.Text = selectedEventRow.cells["FirstNmae"].Text;

but this produces an error saying that it requires an [int] ?

How can I reference by name instead of index number?

Thanks,

Jeff
 
How can I reference by name instead of index number?

You can't, at least, not directly... By that, I mean there is no built-in
way to do what you want, so you'd have to write one of your own.

However, since you're doing this across pages, this will prove to be quite
challenging, I think, and probably not worth the effort...
 
Back
Top