Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Getting the value of invisible columns/cells

Reply
Thread Tools

Getting the value of invisible columns/cells

 
 
JLeary
Guest
Posts: n/a
 
      07-29-2003

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!



 
Reply With Quote
 
 
 
 
John
Guest
Posts: n/a
 
      07-30-2003
IAre you accessing value as string x=Colname.Text, or just string x=Colname?

John
http://mallsocket.com

"JLeary" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> 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!
>
>
>



 
Reply With Quote
 
 
 
 
Lewis Wang [MSFT]
Guest
Posts: n/a
 
      07-30-2003
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" <(E-Mail Removed)>
| | 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: <(E-Mail Removed)>
| | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
| | NNTP-Posting-Host: host-216-57-145-64.customer.veroxity.net
216.57.145.64
| | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5911
| | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
| |
| |
| | 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!
| |
| |
| |
| |
|

 
Reply With Quote
 
Lewis Wang [MSFT]
Guest
Posts: n/a
 
      07-30-2003
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.datagridc ontrol
| From: http://www.velocityreviews.com/forums/(E-Mail 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.datagridc ontrol
| 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" <(E-Mail Removed)>
| | | 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: <(E-Mail Removed)>
| | | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
| | | NNTP-Posting-Host: host-216-57-145-64.customer.veroxity.net
| 216.57.145.64
| | | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| | | Xref: cpmsftngxa06.phx.gbl
| | microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5911
| | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
| | |
| | |
| | | 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!
| | |
| | |
| | |
| | |
| |
|

 
Reply With Quote
 
JLeary
Guest
Posts: n/a
 
      07-30-2003

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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.datagridc ontrol
> | From: (E-Mail 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.datagridc ontrol
> | 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" <(E-Mail Removed)>
> | | | 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: <(E-Mail Removed)>
> | | | Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
> | | | NNTP-Posting-Host: host-216-57-145-64.customer.veroxity.net
> | 216.57.145.64
> | | | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
> | | | Xref: cpmsftngxa06.phx.gbl
> | | microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5911
> | | | X-Tomcat-NG:

microsoft.public.dotnet.framework.aspnet.datagridc ontrol
> | | |
> | | |
> | | | 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!
> | | |
> | | |
> | | |
> | | |
> | |
> |
>



 
Reply With Quote
 
Lewis Wang [MSFT]
Guest
Posts: n/a
 
      07-31-2003
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" <(E-Mail Removed)>
| References: <(E-Mail Removed)>
<(E-Mail Removed)>
<#(E-Mail Removed)>
<(E-Mail Removed)>
| 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#(E-Mail Removed)>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
| NNTP-Posting-Host: host-216-57-145-64.customer.veroxity.net 216.57.145.64
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5939
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
|
|
| 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]" <(E-Mail Removed)> wrote in message
| news:(E-Mail Removed)...
| > 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.datagridc ontrol
| > | From: (E-Mail 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.datagridc ontrol
| > | 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" <(E-Mail Removed)>
| > | | | 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: <(E-Mail Removed)>
| > | | | Newsgroups:
microsoft.public.dotnet.framework.aspnet.datagridc ontrol
| > | | | NNTP-Posting-Host: host-216-57-145-64.customer.veroxity.net
| > | 216.57.145.64
| > | | | Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| > | | | Xref: cpmsftngxa06.phx.gbl
| > | | microsoft.public.dotnet.framework.aspnet.datagridc ontrol:5911
| > | | | X-Tomcat-NG:
| microsoft.public.dotnet.framework.aspnet.datagridc ontrol
| > | | |
| > | | |
| > | | | 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!
| > | | |
| > | | |
| > | | |
| > | | |
| > | |
| > |
| >
|
|
|

 
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
Making 1 control invisible while showing another in the exact location of the invisible one Andy B ASP .Net 5 05-29-2008 03:08 AM
Invisible - Succinic acid : (AMBER ACID) Invisible krithika.143@gmail.com C++ 0 04-14-2008 06:59 PM
know value of invisible column in gridview Mariano ASP .Net 2 07-19-2007 05:40 PM
Get value if invisible ghostwolf ASP .Net Datagrid Control 3 08-03-2006 08:03 PM
How to transfer a value from an Invisible Grid to an visible Grid =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?= ASP .Net 2 10-17-2005 03:56 AM



Advertisments