Click here to Skip to main content
12,553,145 members (54,431 online)
Rate this:
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 8:19am
Updated 22-Feb-13 9:27am
joshrduncan2012 22-Feb-13 14:53pm
Can you provide code as to what the issues you are referencing refers to?
richcb 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161021.1 | Last Updated 23 Feb 2013
Copyright © CodeProject, 1999-2016
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