我試圖訪問第一小區的整數值,但我得到這個錯誤:訪問的GridView細胞珍惜
Unable to cast object of type 'System.Web.UI.WebControls.DataControlFieldCell' to type 'System.IConvertible'.
,我有存儲在單元格中值是像810
的ID我的代碼
int myID = Convert.ToInt32(GridView1.Rows[rowIndex].Cells[0]);
我試圖訪問第一小區的整數值,但我得到這個錯誤:訪問的GridView細胞珍惜
Unable to cast object of type 'System.Web.UI.WebControls.DataControlFieldCell' to type 'System.IConvertible'.
,我有存儲在單元格中值是像810
的ID我的代碼
int myID = Convert.ToInt32(GridView1.Rows[rowIndex].Cells[0]);
Cells[0]
返回DataControlFieldCell
對象,而不是單元格的值。
使用該單元的Text
屬性。
GridView1.Rows[rowIndex].Cells[0].Text
- 或 -
GridView1.Rows[rowIndex].Cells[0].Value
使編程人員的生活困難與微軟一段時間推出這些愚蠢的含糊之處。
試試這個這兩個代碼的價值
int SB = Convert.ToInt32(gdTest.SelectedRow.Cells[1].Text);
---------OR-------
int AS = Convert.ToInt32(gdTest.Rows[1].Cells[1].Text);
好吧,這並不能幫助我,我應該怎麼用?我是新來的C#。謝謝 – user710502
'Convert.ToInt32(GridView1.Rows [rowIndex] .Cells [0] .Text)' – SLaks
謝謝,感謝您的幫助 – user710502