Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Gridview - Accessing a field value in current row

Reply
Thread Tools

Gridview - Accessing a field value in current row

 
 
Joe Reiss
Guest
Posts: n/a
 
      01-03-2006
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


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      01-03-2006
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" <> wrote in message
news:0Sjuf.100425$ ...
> 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
>



 
Reply With Quote
 
 
 
 
Joe Reiss
Guest
Posts: n/a
 
      01-03-2006
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" <> wrote in message
news:...
> 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" <> wrote in message
> news:0Sjuf.100425$ ...
>> 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
>>

>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      01-04-2006
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" <> wrote in message
news:_ZCuf.10806$.. .
> 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" <> wrote in message
> news:...
>> 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" <> wrote in message
>> news:0Sjuf.100425$ ...
>>> 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
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript validation for a not required field, field is onlyrequired if another field has a value jr Javascript 3 07-08-2010 10:33 AM
Gridview row databound event - can't get past the 1st row of gridview maurban@gmail.com ASP .Net 5 10-13-2006 09:37 PM
GridView nested in DataList - refreshing corresponding DataList row after updating GridView row H5N1 ASP .Net 0 04-26-2006 11:41 PM
Change style of a single row of the item list of datagrid, based on a field value of current item... QUASAR ASP .Net Datagrid Control 6 01-17-2004 07:46 PM
If value in name field in top row disable submit button until add button is pressed or field is cleared. Chuck Javascript 0 11-10-2003 02:23 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57