2011-09-23 74 views
4

我试图访问第一小区的整数值,但我得到这个错误:访问的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]); 

回答

6

Cells[0]返回DataControlFieldCell对象,而不是单元格的值。
使用该单元的Text属性。

+0

好吧,这并不能帮助我,我应该怎么用?我是新来的C#。谢谢 – user710502

+3

'Convert.ToInt32(GridView1.Rows [rowIndex] .Cells [0] .Text)' – SLaks

+0

谢谢,感谢您的帮助 – user710502

5
GridView1.Rows[rowIndex].Cells[0].Text 

- 或 -

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

使编程人员的生活困难与微软一段时间推出这些愚蠢的含糊之处。

0

试试这个这两个代码的价值

int SB = Convert.ToInt32(gdTest.SelectedRow.Cells[1].Text); 

       ---------OR------- 

int AS = Convert.ToInt32(gdTest.Rows[1].Cells[1].Text);