当前位置:编程学习 > C#/ASP.NET >>

关于获取Gridview某行某列的值问题,请高手指教?

我做了一个gridview,设置了修改功能,修改了某个行某列值(值类型是decimal),然后想在更新之前获取修改后的值,但是提取的时候是提示空,提取其它字符型的数值就可以,为什么呢?请搞手提教,非常感谢。
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        database db = new database();
        SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
        strcon.Open();
        string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
        number = Convert.ToInt32(this.GridView1.Rows[e.RowIndex].Cells[4].Text);这句提取后值是""        
        jc_id = Convert.ToInt32(this.GridView1.Rows[e.RowIndex].Cells[7].Text);这句提取后就是2389        string scd = "select number from tjdg_fx where ds_id=" + id;
        number_old=(int.Parse(db.rowFirst(scd).ToString()));
.......
--------------------编程问答-------------------- + Convert.ToInt32(this.GridView1.Rows[e.RowIndex].Cells[4].Text) “Convert.ToInt32(this.GridView1.Rows[e.RowIndex].Cells[4].Text)”引发了“System.FormatException”类型的异常 int {System.FormatException}
提示以上出错 --------------------编程问答-------------------- Cells[4].Text是什么,不符合转换吧 --------------------编程问答-------------------- 我输入的是50,数字 --------------------编程问答-------------------- 看看this.GridView1.Rows[e.RowIndex].Cells[4].Text是不是数字,根据错误提示,其值不是数字类型,不能转换。

this.GridView1.Rows[e.RowIndex].Cells[4]如果有多控件,不能简单.Text方式获取值,要先findControl

string tmp = (this.GridView1.Rows[e.RowIndex].FindControl("controlID") as TextBox).Text;
的方式获取。 --------------------编程问答-------------------- FindControl --------------------编程问答-------------------- 你可以取查看一下这个页面的源文件,看看到底是你取错了cells,还是数据转换的有问题 --------------------编程问答-------------------- 数据库为number型的,查询出来自动绑定给控件默认是 double类型
--------------------编程问答-------------------- 4楼方法值得一试
引用 4 楼  的回复:
看看this.GridView1.Rows[e.RowIndex].Cells[4].Text是不是数字,根据错误提示,其值不是数字类型,不能转换。

this.GridView1.Rows[e.RowIndex].Cells[4]如果有多控件,不能简单.Text方式获取值,要先findControl

string tmp = (this.GridView1.Rows[e.RowInd……
--------------------编程问答-------------------- 把它转变成模板列,在前台代码中找到相对应的textbox,取textbox的值就行了。
=Convert.ToInt32((grd_users.Rows[e.RowIndex].FindControl("TextBox1") as TextBox).Text); --------------------编程问答-------------------- 先打印值出来试试,再转类型吧。 --------------------编程问答-------------------- number = Convert.ToInt32((this.GridView1.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox).Text); --------------------编程问答-------------------- .value.text --------------------编程问答-------------------- number = Convert.ToInt32((this.GridView1.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox).Text);
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,