Getting the value of invisible columns/cells

J

JLeary

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

Lewis Wang [MSFT]

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" <[email protected]>
| | 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: <[email protected]>
| | 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!
| |
| |
| |
| |
|
 
L

Lewis Wang [MSFT]

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: (e-mail address removed) (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" <[email protected]>
| | | 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: <[email protected]>
| | | 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!
| | |
| | |
| | |
| | |
| |
|
 
J

JLeary

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 said:
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: (e-mail address removed) (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" <[email protected]>
| | | 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: <[email protected]>
| | | 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!
| | |
| | |
| | |
| | |
| |
|
 
L

Lewis Wang [MSFT]

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" <[email protected]>
| References: <[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
| 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#[email protected]>
| 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.
|
| | > 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: (e-mail address removed) (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" <[email protected]>
| > | | | 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: <[email protected]>
| > | | | 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!
| > | | |
| > | | |
| > | | |
| > | | |
| > | |
| > |
| >
|
|
|
 

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,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top