Getting the value of invisible columns/cells

Discussion in 'ASP .Net Datagrid Control' started by JLeary, Jul 29, 2003.

  1. JLeary

    JLeary Guest

    Hi all,

    What is the best way to get the value of hidden columns in a datagrid. I've
    read a few articles, but the approaches don't seem very clear. I've
    basically got a result set with an autoincrement key and two foreign keys
    that are automatically populated when a row is added. I do not want to show
    these columns in the datagrid. When I try to access the grid values on
    update they return null for these columns, unless I make them visible.

    Thanks in advance for any suggestions!
    JLeary, Jul 29, 2003
    #1
    1. Advertising

  2. JLeary

    John Guest

    IAre you accessing value as string x=Colname.Text, or just string x=Colname?

    John
    http://mallsocket.com

    "JLeary" <> wrote in message
    news:...
    >
    > Hi all,
    >
    > What is the best way to get the value of hidden columns in a datagrid.

    I've
    > read a few articles, but the approaches don't seem very clear. I've
    > basically got a result set with an autoincrement key and two foreign keys
    > that are automatically populated when a row is added. I do not want to

    show
    > these columns in the datagrid. When I try to access the grid values on
    > update they return null for these columns, unless I make them visible.
    >
    > Thanks in advance for any suggestions!
    >
    >
    >
    John, Jul 30, 2003
    #2
    1. Advertising

  3. Hi JLeary,

    Sorry that I misunderstood you in the prior post, I reproduced this problem
    on my side, and we can use the following method to resolve this problem.

    1. Change all hidden columns to template columns. You can easily do this in
    the properties builder of the datagrid. Select the columns tab, click one
    hidden column in the "Select columns"listbox, and you will find a "convert
    this column to a template column" link upon the "OK" button. Click the link
    then click OK.

    2. In the code behind, in Onupdate method, we can get the value of hidden
    columns on the edit row, something like this:

    Label label1=(Label)DataGrid1.Items[2].Cells[0].Controls[1];
    //DataGrid1.EditItemIndex=2;
    string s=label1.Text;

    Please note that we need to use "1" as the subscription in the Controls
    collection (Controls[1]), because the label control is the second control
    of the cell.

    Hope this helps.

    Best Regards,
    Lewis

    Get Secure! - www.microsoft.com/security
    This posting is provided "AS IS" with no warranties, and confers no rights.


    --------------------
    | --------------------
    | | From: "JLeary" <>
    | | Subject: Getting the value of invisible columns/cells
    | | Date: Tue, 29 Jul 2003 12:05:55 -0400
    | | Lines: 14
    | | X-Priority: 3
    | | X-MSMail-Priority: Normal
    | | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    | | Message-ID: <>
    | | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | | NNTP-Posting-Host: host-216-57-145-64.customer.veroxity.net
    216.57.145.64
    | | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    | | Xref: cpmsftngxa06.phx.gbl
    | microsoft.public.dotnet.framework.aspnet.datagridcontrol:5911
    | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | |
    | |
    | | Hi all,
    | |
    | | What is the best way to get the value of hidden columns in a datagrid.
    | I've
    | | read a few articles, but the approaches don't seem very clear. I've
    | | basically got a result set with an autoincrement key and two foreign
    keys
    | | that are automatically populated when a row is added. I do not want to
    | show
    | | these columns in the datagrid. When I try to access the grid values on
    | | update they return null for these columns, unless I make them visible.
    | |
    | | Thanks in advance for any suggestions!
    | |
    | |
    | |
    | |
    |
    Lewis Wang [MSFT], Jul 30, 2003
    #3
  4. In addition, after converting hidden columns to template columns, we also
    need to delete EditItemTemplate of thses template column; otherwise there
    will be a cast exception. We can do it like this: right click the datagrid
    and move to "Edit Template", then select one of hidden columns in the pop
    up menu, delete the textbox in the EditItemTemplate cell.

    Please let me know if it works. Thanks.

    Lewis

    --------------------
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | From: (Lewis Wang [MSFT])
    | Organization: Microsoft
    | Date: Wed, 30 Jul 2003 13:14:02 GMT
    | Subject: RE: Getting the value of invisible columns/cells
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | MIME-Version: 1.0
    | Content-Type: text/plain
    | Content-Transfer-Encoding: 7bit
    |
    | Hi JLeary,
    |
    | Sorry that I misunderstood you in the prior post, I reproduced this
    problem
    | on my side, and we can use the following method to resolve this problem.
    |
    | 1. Change all hidden columns to template columns. You can easily do this
    in
    | the properties builder of the datagrid. Select the columns tab, click one
    | hidden column in the "Select columns"listbox, and you will find a
    "convert
    | this column to a template column" link upon the "OK" button. Click the
    link
    | then click OK.
    |
    | 2. In the code behind, in Onupdate method, we can get the value of hidden
    | columns on the edit row, something like this:
    |
    | Label label1=(Label)DataGrid1.Items[2].Cells[0].Controls[1];
    | //DataGrid1.EditItemIndex=2;
    | string s=label1.Text;
    |
    | Please note that we need to use "1" as the subscription in the Controls
    | collection (Controls[1]), because the label control is the second control
    | of the cell.
    |
    | Hope this helps.
    |
    | Best Regards,
    | Lewis
    |
    | Get Secure! - www.microsoft.com/security
    | This posting is provided "AS IS" with no warranties, and confers no
    rights.
    |
    |
    | --------------------
    | | --------------------
    | | | From: "JLeary" <>
    | | | Subject: Getting the value of invisible columns/cells
    | | | Date: Tue, 29 Jul 2003 12:05:55 -0400
    | | | Lines: 14
    | | | X-Priority: 3
    | | | X-MSMail-Priority: Normal
    | | | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    | | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    | | | Message-ID: <>
    | | | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | | | NNTP-Posting-Host: host-216-57-145-64.customer.veroxity.net
    | 216.57.145.64
    | | | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    | | | Xref: cpmsftngxa06.phx.gbl
    | | microsoft.public.dotnet.framework.aspnet.datagridcontrol:5911
    | | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | | |
    | | |
    | | | Hi all,
    | | |
    | | | What is the best way to get the value of hidden columns in a
    datagrid.
    | | I've
    | | | read a few articles, but the approaches don't seem very clear. I've
    | | | basically got a result set with an autoincrement key and two foreign
    | keys
    | | | that are automatically populated when a row is added. I do not want
    to
    | | show
    | | | these columns in the datagrid. When I try to access the grid values on
    | | | update they return null for these columns, unless I make them visible.
    | | |
    | | | Thanks in advance for any suggestions!
    | | |
    | | |
    | | |
    | | |
    | |
    |
    Lewis Wang [MSFT], Jul 30, 2003
    #4
  5. JLeary

    JLeary Guest

    Thanks Lewis...I had come across a similar posting last evening. This does
    work; however, I'm not sure why it is necessary. Your help is appreciated.

    "Lewis Wang [MSFT]" <> wrote in message
    news:...
    > In addition, after converting hidden columns to template columns, we also
    > need to delete EditItemTemplate of thses template column; otherwise there
    > will be a cast exception. We can do it like this: right click the datagrid
    > and move to "Edit Template", then select one of hidden columns in the pop
    > up menu, delete the textbox in the EditItemTemplate cell.
    >
    > Please let me know if it works. Thanks.
    >
    > Lewis
    >
    > --------------------
    > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    > | From: (Lewis Wang [MSFT])
    > | Organization: Microsoft
    > | Date: Wed, 30 Jul 2003 13:14:02 GMT
    > | Subject: RE: Getting the value of invisible columns/cells
    > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    > | MIME-Version: 1.0
    > | Content-Type: text/plain
    > | Content-Transfer-Encoding: 7bit
    > |
    > | Hi JLeary,
    > |
    > | Sorry that I misunderstood you in the prior post, I reproduced this
    > problem
    > | on my side, and we can use the following method to resolve this problem.
    > |
    > | 1. Change all hidden columns to template columns. You can easily do this
    > in
    > | the properties builder of the datagrid. Select the columns tab, click

    one
    > | hidden column in the "Select columns"listbox, and you will find a
    > "convert
    > | this column to a template column" link upon the "OK" button. Click the
    > link
    > | then click OK.
    > |
    > | 2. In the code behind, in Onupdate method, we can get the value of

    hidden
    > | columns on the edit row, something like this:
    > |
    > | Label label1=(Label)DataGrid1.Items[2].Cells[0].Controls[1];
    > | //DataGrid1.EditItemIndex=2;
    > | string s=label1.Text;
    > |
    > | Please note that we need to use "1" as the subscription in the Controls
    > | collection (Controls[1]), because the label control is the second

    control
    > | of the cell.
    > |
    > | Hope this helps.
    > |
    > | Best Regards,
    > | Lewis
    > |
    > | Get Secure! - www.microsoft.com/security
    > | This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    > |
    > |
    > | --------------------
    > | | --------------------
    > | | | From: "JLeary" <>
    > | | | Subject: Getting the value of invisible columns/cells
    > | | | Date: Tue, 29 Jul 2003 12:05:55 -0400
    > | | | Lines: 14
    > | | | X-Priority: 3
    > | | | X-MSMail-Priority: Normal
    > | | | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > | | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > | | | Message-ID: <>
    > | | | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    > | | | NNTP-Posting-Host: host-216-57-145-64.customer.veroxity.net
    > | 216.57.145.64
    > | | | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    > | | | Xref: cpmsftngxa06.phx.gbl
    > | | microsoft.public.dotnet.framework.aspnet.datagridcontrol:5911
    > | | | X-Tomcat-NG:

    microsoft.public.dotnet.framework.aspnet.datagridcontrol
    > | | |
    > | | |
    > | | | Hi all,
    > | | |
    > | | | What is the best way to get the value of hidden columns in a
    > datagrid.
    > | | I've
    > | | | read a few articles, but the approaches don't seem very clear. I've
    > | | | basically got a result set with an autoincrement key and two foreign
    > | keys
    > | | | that are automatically populated when a row is added. I do not want
    > to
    > | | show
    > | | | these columns in the datagrid. When I try to access the grid values

    on
    > | | | update they return null for these columns, unless I make them

    visible.
    > | | |
    > | | | Thanks in advance for any suggestions!
    > | | |
    > | | |
    > | | |
    > | | |
    > | |
    > |
    >
    JLeary, Jul 30, 2003
    #5
  6. Hi JLeary,

    By default, when a datagrid is in edit mode, the text of a bound column in
    the edit line is changed into a Textbox automatically and the text's value
    is put into the Textbox(not ViewStat). If the bound column is a hidden
    column, the Textbox will not be rendered to client. So, value in the
    TextBox is also lost. When the page postback, we can't get that value .

    One resolution to deal with this is described in my prior post. It forces
    the label control to be created in the cell. Although this column is
    hidden, the value is stored in ViewStat. When it postback, it loads
    ViewStat and puts this value back to datagrid. So we can get it in the code.

    Another method to walk around this problem is getting the value from
    dataset which is binding to the datagrid.

    Best Regards,
    Lewis

    Get Secure! - www.microsoft.com/security <http://www.microsoft.com/security>
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------
    | From: "JLeary" <>
    | References: <>
    <>
    <#>
    <>
    | Subject: Re: Getting the value of invisible columns/cells
    | Date: Wed, 30 Jul 2003 14:40:25 -0400
    | Lines: 113
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    | Message-ID: <Oj#>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | NNTP-Posting-Host: host-216-57-145-64.customer.veroxity.net 216.57.145.64
    | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
    | Xref: cpmsftngxa06.phx.gbl
    microsoft.public.dotnet.framework.aspnet.datagridcontrol:5939
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    |
    |
    | Thanks Lewis...I had come across a similar posting last evening. This does
    | work; however, I'm not sure why it is necessary. Your help is appreciated.
    |
    | "Lewis Wang [MSFT]" <> wrote in message
    | news:...
    | > In addition, after converting hidden columns to template columns, we
    also
    | > need to delete EditItemTemplate of thses template column; otherwise
    there
    | > will be a cast exception. We can do it like this: right click the
    datagrid
    | > and move to "Edit Template", then select one of hidden columns in the
    pop
    | > up menu, delete the textbox in the EditItemTemplate cell.
    | >
    | > Please let me know if it works. Thanks.
    | >
    | > Lewis
    | >
    | > --------------------
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | > | From: (Lewis Wang [MSFT])
    | > | Organization: Microsoft
    | > | Date: Wed, 30 Jul 2003 13:14:02 GMT
    | > | Subject: RE: Getting the value of invisible columns/cells
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | > | MIME-Version: 1.0
    | > | Content-Type: text/plain
    | > | Content-Transfer-Encoding: 7bit
    | > |
    | > | Hi JLeary,
    | > |
    | > | Sorry that I misunderstood you in the prior post, I reproduced this
    | > problem
    | > | on my side, and we can use the following method to resolve this
    problem.
    | > |
    | > | 1. Change all hidden columns to template columns. You can easily do
    this
    | > in
    | > | the properties builder of the datagrid. Select the columns tab, click
    | one
    | > | hidden column in the "Select columns"listbox, and you will find a
    | > "convert
    | > | this column to a template column" link upon the "OK" button. Click the
    | > link
    | > | then click OK.
    | > |
    | > | 2. In the code behind, in Onupdate method, we can get the value of
    | hidden
    | > | columns on the edit row, something like this:
    | > |
    | > | Label label1=(Label)DataGrid1.Items[2].Cells[0].Controls[1];
    | > | //DataGrid1.EditItemIndex=2;
    | > | string s=label1.Text;
    | > |
    | > | Please note that we need to use "1" as the subscription in the
    Controls
    | > | collection (Controls[1]), because the label control is the second
    | control
    | > | of the cell.
    | > |
    | > | Hope this helps.
    | > |
    | > | Best Regards,
    | > | Lewis
    | > |
    | > | Get Secure! - www.microsoft.com/security
    | > | This posting is provided "AS IS" with no warranties, and confers no
    | > rights.
    | > |
    | > |
    | > | --------------------
    | > | | --------------------
    | > | | | From: "JLeary" <>
    | > | | | Subject: Getting the value of invisible columns/cells
    | > | | | Date: Tue, 29 Jul 2003 12:05:55 -0400
    | > | | | Lines: 14
    | > | | | X-Priority: 3
    | > | | | X-MSMail-Priority: Normal
    | > | | | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    | > | | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    | > | | | Message-ID: <>
    | > | | | Newsgroups:
    microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | > | | | NNTP-Posting-Host: host-216-57-145-64.customer.veroxity.net
    | > | 216.57.145.64
    | > | | | Path:
    cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    | > | | | Xref: cpmsftngxa06.phx.gbl
    | > | | microsoft.public.dotnet.framework.aspnet.datagridcontrol:5911
    | > | | | X-Tomcat-NG:
    | microsoft.public.dotnet.framework.aspnet.datagridcontrol
    | > | | |
    | > | | |
    | > | | | Hi all,
    | > | | |
    | > | | | What is the best way to get the value of hidden columns in a
    | > datagrid.
    | > | | I've
    | > | | | read a few articles, but the approaches don't seem very clear.
    I've
    | > | | | basically got a result set with an autoincrement key and two
    foreign
    | > | keys
    | > | | | that are automatically populated when a row is added. I do not
    want
    | > to
    | > | | show
    | > | | | these columns in the datagrid. When I try to access the grid
    values
    | on
    | > | | | update they return null for these columns, unless I make them
    | visible.
    | > | | |
    | > | | | Thanks in advance for any suggestions!
    | > | | |
    | > | | |
    | > | | |
    | > | | |
    | > | |
    | > |
    | >
    |
    |
    |
    Lewis Wang [MSFT], Jul 31, 2003
    #6
    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.
Similar Threads
  1. Replies:
    0
    Views:
    526
  2. Dot Net Daddy

    Invisible Cells in GridView

    Dot Net Daddy, Aug 15, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    407
    Mark Rae
    Aug 15, 2006
  3. Andy B
    Replies:
    5
    Views:
    591
    Andy B
    May 29, 2008
  4. Joel Finkel

    Cells[].Text or Cells[].Controls[0]

    Joel Finkel, Sep 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    310
    Joel Finkel
    Sep 1, 2003
  5. Olivier Matrot

    How to embed invisible data in cells

    Olivier Matrot, Jul 21, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    4
    Views:
    154
    Steven Cheng[MSFT]
    Jul 25, 2005
Loading...

Share This Page