Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB ASP.NET .NET4.5
Hello all, I have a gridview being populated by a database. Just one column in gridview with a select link. I am trying to retrieve a value from the gridview when the user clicks on Select. I have tried GridView1.SelectedValue.Cells(0).Text and Gridview1.SelectedRow.Cells(1).Text in the code for button click and I am getting "Object variable or With block variable not set." and NullReferenceException Unhandled by user code. Any help would be greatly appreciated. This is not home work. I had ASP.NET and VB6 back in 2003.
This is what I have:
Dim query As String = "select Approved from tablename where [name] = '" & Session("name") & "' And Book= '" & GridView1.SelectedValue.Cells(0).Text & "'"

Posted 22-Feb-13 9:19am
Edited 22-Feb-13 10:27am
joshrduncan2012 at 22-Feb-13 14:53pm
Can you provide code as to what the issues you are referencing refers to?
richcb at 22-Feb-13 15:34pm
You will have to post more code than that. But I can tell you that the gridview.selectedvalue does not have an attribute of .Cells but gridview1.SelectedRow does. Try this:

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

GridView1.SelectedValue gives the datakey value of Selected Row not the actual row but  Gridview1.SelectedRow.Cells(1).Text should work,check whether any row is selected or not,for that check the selected index. 
Can try it too:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 520
1 Maciej Los 205
2 Suvendu Shekhar Giri 159
3 Peter Leow 140
4 Kornfeld Eliyahu Peter 133
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 8,895
2 Peter Leow 5,044
3 Kornfeld Eliyahu Peter 3,333
4 Maciej Los 2,561

Advertise | Privacy | Mobile
Web01 | 2.8.150327.1 | Last Updated 23 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100