GridView Value Cell Access

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

Cannot pass an object of type "System.Web.UI.WebControls.DataControlFieldCell" to enter "System.IConvertible".

And the value that I saved in this cell is an identifier of type 810

My code

int myID = Convert.ToInt32(GridView1.Rows[rowIndex].Cells[0]); 
+4
source share
3 answers

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

+6
source
 GridView1.Rows[rowIndex].Cells[0].Text 

- or -

 GridView1.Rows[rowIndex].Cells[0].Value 

Makes the programmerโ€™s life more complicated with these silly ambiguities that Microsoft has introduced over time.

+5
source

Try both of these codes to be rated.

  int SB = Convert.ToInt32(gdTest.SelectedRow.Cells[1].Text); ---------OR------- int AS = Convert.ToInt32(gdTest.Rows[1].Cells[1].Text); 
0
source

All Articles