Gridview - Accessing a field value in current row

J

Joe Reiss

Hi all,

I can currently access a row value using the following:

GridViewRow g = g.Rows[1];
string s = g.Cells[1].Text;

However, I need this particular field to be invisible. I only put it in the
grid because I need to do stuff with its value, but, the user doesn't need
to see it. However, when a field is invisible the Cells collection doesn't
see it. Anyone have any suggestions?

TIA,
Joe
 
T

Teemu Keiski

Hi,

invisible fields are not kept in ViewState. Therefore you need to add the
field to DataKeyNames of the GridView so that it is kept over postbacks
while the field is invisible.
 
J

Joe Reiss

This particular field is not a key for this grid. There is already another
field that is the key.

Any other suggestions?

Thanx,
Joe

Teemu Keiski said:
Hi,

invisible fields are not kept in ViewState. Therefore you need to add the
field to DataKeyNames of the GridView so that it is kept over postbacks
while the field is invisible.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

Joe Reiss said:
Hi all,

I can currently access a row value using the following:

GridViewRow g = g.Rows[1];
string s = g.Cells[1].Text;

However, I need this particular field to be invisible. I only put it in
the grid because I need to do stuff with its value, but, the user doesn't
need to see it. However, when a field is invisible the Cells collection
doesn't see it. Anyone have any suggestions?

TIA,
Joe
 
T

Teemu Keiski

That doesn't actually mind, GridView does not check for uniqueness, I dare
to doubt and you can have multiple key columns with GridView. It's just the
simplest solution :) Check following ASP.NEt Forum post for reference:
http://forums.asp.net/937935/ShowPost.aspx

If you want to, you can try having a TemplateField, a Label in it and bind
the field as Text to that Label. Then you could access the value from that
field.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

Joe Reiss said:
This particular field is not a key for this grid. There is already
another field that is the key.

Any other suggestions?

Thanx,
Joe

Teemu Keiski said:
Hi,

invisible fields are not kept in ViewState. Therefore you need to add the
field to DataKeyNames of the GridView so that it is kept over postbacks
while the field is invisible.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

Joe Reiss said:
Hi all,

I can currently access a row value using the following:

GridViewRow g = g.Rows[1];
string s = g.Cells[1].Text;

However, I need this particular field to be invisible. I only put it in
the grid because I need to do stuff with its value, but, the user
doesn't need to see it. However, when a field is invisible the Cells
collection doesn't see it. Anyone have any suggestions?

TIA,
Joe
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top