473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

get value of a cell in a gridview

Hi,
How can I get the value of a cell that belongs to a hidden column of
gridview ?
Here's how I normally access the value of a cell, but it doesn't work
if the column is invisible:

Code :
Me.grdPublication.SelectedRow.Cells(1).Text

I've used a gridview with auto-generated columns to false, so I can
display those I want only. Yet the column that are not visible, do
exist, but the text value is always "".

Can you help ?

May 22 '06 #1
8 14762
"graphicsxp" <sa*************@googlemail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Can you help ?


I certainly can! What you've stumbled on is a new feature of the GridView
object, which differs from the DataGrid object in v1.x

Basically, Microsoft have decided that hidden columns in DataGrids were
almost always used to store primary keys of records, and that maintaining
them in ViewState represented a security risk. Therefore, in the GridView
object introduced in v2, hidden columns have been removed from ViewState by
default, which is why the columns themselves are still there (otherwise you
couldn't reference them in the CodeFile), but their values are blank.

Fortunately, there is an easy workaround. Simply set the column(s) to
Visible immediately before invoking the GridView's DataBind() method, and
then hide them again immediately after. E.g.

MyGridView.DataSource = <some sort of DataSet, SqlDataReader, whatever>
MyGridView.Columns[0].Visible = true;
MyGridView.DataBind();
MyGridView.Columns[0].Visible = false;
May 22 '06 #2
hu ??? I can't try right now, will give it a go tomorrow at work. But
it seems totally weird to me. I don't see how that can do the trick!
Hopefully you are right !

May 22 '06 #3
On 22 May 2006 13:52:00 -0700, "graphicsxp"
<sa*************@googlemail.com> wrote:
Hi,
How can I get the value of a cell that belongs to a hidden column of
gridview ?
Here's how I normally access the value of a cell, but it doesn't work
if the column is invisible:

Code :
Me.grdPublication.SelectedRow.Cells(1).Text

I've used a gridview with auto-generated columns to false, so I can
display those I want only. Yet the column that are not visible, do
exist, but the text value is always "".

Can you help ?


another easy way to make them accessible is to add the column to the
gridview attribute datakeynames. (ie:
datakeynames=[address,city,salary,id])
Peter Kellner
http://peterkellner.net
May 22 '06 #4
yeah probably I should do that. I did it for the primary key, can't
remember why i didn't do it for the other 'hidden' fields

May 22 '06 #5
"graphicsxp" <sa*************@googlemail.com> wrote in message
news:11*********************@j73g2000cwa.googlegro ups.com...
But it seems totally weird to me.
Really? Seems perfectly logical to me...
I don't see how that can do the trick!
OK.
Hopefully you are right !


Let's hope so!
May 22 '06 #6
K B
IMHO this is the easiest way. This way you don't have to play with your
column settings and you can still hide the column. You MUST have
DataKeyNames set in your gridview HTML.

Dim key As DataKey = gvQuestions.SelectedDataKey
Session("QuestionID") = key.Value

HTH,
Kit

*** Sent via Developersdex http://www.developersdex.com ***
May 22 '06 #7
What is the point of having a visible property to the column if it
doesn't do anything? All this serves to do is confuse developers who
have for years stored data in hidden fields with the expecation that
they can access it programatically.

Furthermore, their PK argument is hogwash as with AJAX style call backs
I can think of very good reasons that people would want to hide a
column only to have a callback retrieve the text of the column on a
callback and display it to the user.

At the very least they should remove the visible property entirely as
it is useless if it doesn't dislay data to the user (expected behavior)
AND doesn't store the data in viewstate.

I'm sorry to say that this is just another example of MSFT missing the
mark which is frustrating as hell for those of us who have relied on
them for so many years for our businesses.

Sean

Mark Rae wrote:
"graphicsxp" <sa*************@googlemail.com> wrote in message
news:11*********************@j73g2000cwa.googlegro ups.com...
But it seems totally weird to me.


Really? Seems perfectly logical to me...
I don't see how that can do the trick!


OK.
Hopefully you are right !


Let's hope so!


May 24 '06 #8
"Stiphy" <st******@yahoo.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...
What is the point of having a visible property to the column if it
doesn't do anything? All this serves to do is confuse developers who
have for years stored data in hidden fields with the expecation that
they can access it programatically.
Things evolve. This behaviour has been identified as a potential security
risk, so has been modified.
At the very least they should remove the visible property entirely as
it is useless if it doesn't dislay data to the user (expected behavior)
AND doesn't store the data in viewstate.
Rubbish! All that has changed is that for GridView columns to store hidden
column data in ViewState, the columns need to be visible at the moment the
data is bound to the DataGrid. They can then be set straight back to hidden
if required. I'm sure you can manage it.
I'm sorry to say that this is just another example of MSFT missing the
mark which is frustrating as hell for those of us who have relied on
them for so many years for our businesses.


Then this tiny change in behaviour really oughtn't to present you with much
of a coding challenge... :-)
May 25 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jon S via DotNetMonster.com | last post by:
HI all, I'm returning a dataset to a gridview control. When the gridview asp.net control is populated from the returning dataset some of the cells remain empty. This is expected as some data...
2
by: loga123 | last post by:
Hi All, I am using Link Button for DELETE on the gridview. When I click on DELETE link, I get the ArgumentOutOfRangeException. But...it deletes the record from table in the database. On...
4
by: pvong | last post by:
Hi, I'm a newbie and I'm looking for some help. I'm programming in VB.Net. I have a simple gridview and when the user hits the Edit link, the gridview changes to edit mode. I replaced the...
3
by: Bill Gower | last post by:
I have an cell which contains a field member which is filled with String.Empty. When I retrieve the value in the cell with Cells.Text.ToString() and try to compare it to String.Empty, I can't...
14
by: Mike | last post by:
I have a gridview that has a button in the last cell of each row. I want to get the text from cell 1 for that row the button was clicked on. So if my gridview looks like this: N-12 BMW ...
1
by: Vyas111111 | last post by:
Hello All, How can i get the value of a gridview cell outside any GridView event
4
by: foolmelon | last post by:
Before AJAX, we were able to focus a cell in a gridview during a fullpage postback. After putting the gridview inside an UpdatePanel, we cannot focus a cell in this gridview anymore. Does anybody...
3
by: jignesh234 | last post by:
Hi all, I am getting trouble in exracting the value of a cell of gridview into a label. here is my code... label1.text=gridview1.selectedrow.cells.text.tostring(); I dont know why I am not...
0
by: Carlos | last post by:
Hi all, I have code that used to work but no longer does when trying to obtain the value of a field in a gridview. I do try to find the value of a field when a checkbox in the same row handles...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.