Need to be able to extract a specific databound cell value from a vb.net gridview control

I need to use a specific value in a cell in a gridview control.   It is a data bound cell. I have a line of code that works and does retrieve a value, but I had to hard code the row number.

test1.text = gvClients.Rows(4).Cells(5).Text.ToString

I have been trying to use some kind of index to replace the number 4 in the above code, but nothing has worked.  

I would really appreciate any feedback

Thanks !
PicGirl100Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
In order for the program to know which row index you want the user will need to select the row. In order to do this, selecting a row, you need to have a Select button on every line of the grid. This button is added the same way you add Edit, Delete buttons on the grid. Once you have that all you need to do is do this.

Dim rowIndex As Integer =  gvClients.SelectedIndex
test1.text = gvClients.Rows(rowIndex).Cells(5).Text.ToString

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
0
PicGirl100Author Commented:
I am sorry I was not more clear.. I do have the select button... I added your code.. and now I get the following error

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

I remember reading that the initial value of the index is -1.. so I am trying to exclude anything with -1.  

I am selecting any row.. using the select button and this happens everytime.. I know I am missing something very simple.. just not sure what..
0
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Fernando SotoRetiredCommented:
Where in your code did you place these two statements:

Dim rowIndex As Integer =  gvClients.SelectedIndex
test1.text = gvClients.Rows(rowIndex).Cells(5).Text.ToString

Open in new window


If you placed it in the Page_Load event that happens before SelectedIndexChanged event happens. I would place the code in the SelectedIndexChanged event handler and then you will see it changed.
0
PicGirl100Author Commented:
In the SelectedIndexChanged of the gridview control... i bet that is the wrong place
0
PicGirl100Author Commented:
ok.. i have it there.. i thought.. but let me double check....
0
PicGirl100Author Commented:
yes.. you are right..  .. I had some goofy link button in the grid.. instead of the select one.. once I corrected that.. it started working.. thanks so much !
0
Fernando SotoRetiredCommented:
Not a problem PicGirl100, glad I was able to help.
0
PicGirl100Author Commented:
thanks so much for the help
0
Fernando SotoRetiredCommented:
Not a problem PicGirl100, glad I was able to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development Software

From novice to tech pro — start learning today.