Click here to Skip to main content
Rate this: bad
good
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 & "'"
 

Thank-you,
D-Bar
Posted 22-Feb-13 8:19am
D-Bar313
Edited 22-Feb-13 9:27am
v2
Comments
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:
 
Gridview1.SelectedRow.Cell[0].ToString();
 

1 solution

Rate this: bad
good
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:
Gridview1.Rows(Gridview1.SelectedIndex).Cells(0).Text;
  Permalink  
v2

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



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