Jack Henry
Jack Henry

Reputation: 302

Not retrieving the correct value from a datagridview column

I am trying to retrieve a value from a column within a data grid view (gv_Quals). I can't seem to find the correct answer online and this is my attempt. The Unit ID is the second column within the Sql Database. The row index is passed down.

 String txtUnitID =gv_Quals.Rows[rowIndex].Cells[1].ToString();

When I try and run this code, txtUnitID will always return this

txtUnitID = "System.Web.UI.WebControls.DataControlFieldCellstring"

when it should be returning 5 as that is the UnitID. I'm I doing it wrong or have I forgot something. Sorry if I seem vague, thanks in advance!

Upvotes: 0

Views: 22

Answers (1)

Kevin Shah
Kevin Shah

Reputation: 1617

If there is DataBound column in your grid than you can get value using

gv_Quals.Rows[rowIndex].Cells[1].Text

Or if its any control then you have to first cast that control and then you can get value from that control.

Upvotes: 1

Related Questions