Gridview - Accessing a field value in current row

Discussion in 'ASP .Net Web Controls' started by Joe Reiss, Jan 3, 2006.

  1. Joe Reiss

    Joe Reiss Guest

    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
     
    Joe Reiss, Jan 3, 2006
    #1
    1. Advertising

  2. Joe Reiss

    Teemu Keiski Guest

    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
    >
     
    Teemu Keiski, Jan 3, 2006
    #2
    1. Advertising

  3. Joe Reiss

    Joe Reiss Guest

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

    >
    >
     
    Joe Reiss, Jan 3, 2006
    #3
  4. Joe Reiss

    Teemu Keiski Guest

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

    >>
    >>

    >
    >
     
    Teemu Keiski, Jan 4, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page