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]);
Cells[0] returns a DataControlFieldCell object, not a cell value.Use the property of the Text cell.
Cells[0]
DataControlFieldCell
Text
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.
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);