Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing GridView Cells Value

I am trying to access the integer value of the first cell but I'm getting this error:

Unable to cast object of type 'System.Web.UI.WebControls.DataControlFieldCell' to type 'System.IConvertible'.

And the value i have stored in that cell is an ID like 810

My Code

int myID = Convert.ToInt32(GridView1.Rows[rowIndex].Cells[0]);
like image 734
user710502 Avatar asked Jan 19 '23 16:01

user710502


1 Answers

Cells[0] returns a DataControlFieldCell object, not the cell's value.
Use the cell's Text property.

like image 82
SLaks Avatar answered Jan 30 '23 14:01

SLaks