Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a non-key dataset field value 1

Status
Not open for further replies.

kidvegas19

Technical User
Dec 31, 2003
28
0
0
US
VWD 2005 Express

For the sake of this discussion, here is the set up:

I have 1 web form. On that web form I have a label, a button, and I have a gridview control bound to an accessdatasource. When I load the form, the data displayed in the gridview is:

Fieldname: Code (Primary Key) Data: 12
Fieldname: Firstname (no key) Data: John
Fieldname: Lastname (no key) Data: Doe

For the sake of this discussion, here is what I want to accomplish:

When I click the button, the label text will change to Doe.

How is this done?

Thanks in advance,

KV
 
Something like this (if the button is on each row of your DataGridView)?

Code:
myLabel.Text = myDataGridView.Rows(e.RowIndex).Columns("Lastname").Value.ToString()

Otherwise, you'll need to pick an arbitrary RowIndex to use.

Hope this helps,

Alex

[small]----signature below----[/small]
I don't do any programming whatsoever

Ignorance of certain subjects is a great part of wisdom
 
Thanks Alex,

The button is outside of the gridview, however, the query returns only 1 row.

If I type in this code:
Label1.Text = GridView1.Rows(e.RowIndex).colums("Lastname").value.tostring()

e.RowIndex is blue underlined with the tool tip "RowIndex is not a member of System.EventsArgs"

If I type in this code:
Label1.Text = GridView1.Rows(0).colums("Lastname").value.tostring()

Gridview1.Rows(0).columns is blue underlined with the tool tip "Columns is not a member of System.UI.WebControls.GridViewRow"

The GridView1 has Select enabled. I tried the same code with the same results in the sub created by double clicking Select:

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged

Again as a reminder, I am working in VWD 2005 Express. Is there limitations in the Express edition that would prevent evaluating a specific field?

Thanks,

KV

 
It seems VB will not let you get at the cells collection (not Columns ;-) ) by name, but I assume your index is 2.

Try this:

Code:
Response.Write(GridView1.Rows(0).Cells(2).Text)

You can use the same expression

Code:
GridView1.Rows(0).Cells(2).Text
To assign the text to your label.

Hope this helps,

Alex

[small]----signature below----[/small]
I don't do any programming whatsoever

Ignorance of certain subjects is a great part of wisdom
 
Thanks AlexCuse - works as advertised.

Very much appreciated.

KV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top