GridviewRow cell reference

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
 
M

Mark Rae [MVP]

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...
 

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,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top