访问 GridView 单元格值 [英] Accessing GridView Cells Value

查看:22
本文介绍了访问 GridView 单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问第一个单元格的整数值,但出现此错误:

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

无法将System.Web.UI.WebControls.DataControlFieldCell"类型的对象转换为System.IConvertible"类型.

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

我在那个单元格中存储的值是一个像 810 这样的 ID

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

我的代码

int myID = Convert.ToInt32(GridView1.Rows[rowIndex].Cells[0]);

推荐答案

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

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

这篇关于访问 GridView 单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆