Gridview not returning data in event

G

Guest

I have a gridview that some boundfield and buttonfield controls. I have a
data element I
1. want to use when the button is clicked for a given row, but
2. dont want it visibly displayed in the gridview
so I created a boundfield with visible=false as the first column (something
I did in the datagrid).
In my RowCommand event I do some processing using the online docs as a
template. The problem is that when I reference the boundfield as
visible=false, no data comes back. If I set it to visible=true, data does
come back. The problem is that I dont want it to show up in the grid, but I
want access to the data.
Is this possible using the boundfield, but is there another alternative in
the gridview?
Thanks, Mark
 
J

Jan Hyde

MarkAurit <[email protected]>'s wild
thoughts were released on Sat, 6 May 2006 09:11:01 -0700
bearing the following fruit:
I have a gridview that some boundfield and buttonfield controls. I have a
data element I
1. want to use when the button is clicked for a given row, but
2. dont want it visibly displayed in the gridview
so I created a boundfield with visible=false as the first column (something
I did in the datagrid).
In my RowCommand event I do some processing using the online docs as a
template. The problem is that when I reference the boundfield as
visible=false, no data comes back. If I set it to visible=true, data does
come back. The problem is that I dont want it to show up in the grid, but I
want access to the data.
Is this possible using the boundfield, but is there another alternative in
the gridview?
Thanks, Mark

sound's like the same question I just answered, so I'll
repost my answer here:

Ok, I'm working from memory here so my facts might be a
little off.

Anyhoo - select your datagrid and press f4, find the
property 'DataKeyNames'

Lets say you want to retrieve CustomerID from the database
but don't want to display it in the grid.

Add 'CustomerID' (without quotes) to the DataKeyNames
collection, repeat this for your other fields.

You can retrieve the data with code something like this

GridView1.DataKeys(RowIndex).Item("CustomerID")

Jan Hyde (VB MVP)
 
G

Guest

Thank you Phillip. Am I correct that this lets you save only 1 column's
value? In my situation the pk is made up of >1 column, so I concatenated
them and made that the DataKey.
 
J

Jan Hyde

MarkAurit <[email protected]>'s wild
thoughts were released on Mon, 8 May 2006 08:20:02 -0700
bearing the following fruit:
Thank you Phillip. Am I correct that this lets you save only 1 column's
value?
No.

J

In my situation the pk is made up of >1 column, so I concatenated
them and made that the DataKey.


Jan Hyde (VB MVP)
 
G

Guest

Hi Mark,

This property takes a comma-separated list of field names and then you would
refer to each key by its index, e.g. GridView1.SelectedDataKey.Values[0] and
GridView1.SelectedDataKey.Values[1] and so on.
 
Joined
Aug 18, 2006
Messages
2
Reaction score
0
=?Utf-8?B?TWFya0F1cml0?= said:
I have a gridview that some boundfield and buttonfield controls. I have a
data element I
1. want to use when the button is clicked for a given row, but
2. dont want it visibly displayed in the gridview
so I created a boundfield with visible=false as the first column (something
I did in the datagrid).
In my RowCommand event I do some processing using the online docs as a
template. The problem is that when I reference the boundfield as
visible=false, no data comes back. If I set it to visible=true, data does
come back. The problem is that I dont want it to show up in the grid, but I
want access to the data.
Is this possible using the boundfield, but is there another alternative in
the gridview?
Thanks, Mark

if you want to get the value of a hidden field it will be best to change it from a boundfield to a template field, then edit the template field and add a label which which is bound to the field from the dataset returned.

then you can get the value of the field as follows:
her is an example from my application

Dim idx As Integer = Convert.ToInt32(e.CommandArgument)
Dim key As DataKey = GridView1.DataKeys(idx)
ID = key.Item("iPKJob").ToString()
Dim lblEmail As Label
lblEmail = GridView1.Rows(idx).FindControl("lblBrokerEmail") '.Cells(11).Text
Dim brokerEmail As String = lblEmail.Text

hope this helps.

mike
 

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,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top