Home All Groups Group Topic Archive Search About

Gridview - Accessing a field value in current row

Author
3 Jan 2006 12:51 AM
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

Author
3 Jan 2006 5:45 PM
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.

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

Show quoteHide quote
"Joe Reiss" <joere***@bellsouth.net> wrote in message
news:0Sjuf.100425$aS5.96213@bignews4.bellsouth.net...
> 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
>
Author
3 Jan 2006 10:36 PM
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

Show quoteHide quote
"Teemu Keiski" <jot***@aspalliance.com> wrote in message
news:eVo9M2IEGHA.3064@TK2MSFTNGP14.phx.gbl...
> 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" <joere***@bellsouth.net> wrote in message
> news:0Sjuf.100425$aS5.96213@bignews4.bellsouth.net...
>> 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
>>
>
>
Author
4 Jan 2006 7:44 PM
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

Show quoteHide quote
"Joe Reiss" <joere***@bellsouth.net> wrote in message
news:_ZCuf.10806$vL4.5887@bignews1.bellsouth.net...
> 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" <jot***@aspalliance.com> wrote in message
> news:eVo9M2IEGHA.3064@TK2MSFTNGP14.phx.gbl...
>> 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" <joere***@bellsouth.net> wrote in message
>> news:0Sjuf.100425$aS5.96213@bignews4.bellsouth.net...
>>> 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
>>>
>>
>>
>
>