取不出gridview textbox里的值了!

来源:百度知道 编辑:UC知道 时间:2024/05/29 20:54:39
忙了一天了都没有找到原因,急啊,高手帮忙。
第二列全是文本框,不管输入什么,读出的字符串都是“”。
string n = ((TextBox)(this.GridView1.Rows[0].Cells[1].FindControl("TextBox1"))).Text.Trim();

TextBox n = GridView1.Rows[e.RowIndex].FindControl("TextBox1") as TextBox;
这是在RowUpdating修改事件里写的方法,里面的“TextBox1”就已经是代表第二列了,就不用再去写Cell【1】了,
如果是普通按钮里写的话
TextBox n = GridView1.Rows[0].Cells[1].FindControl("TextBox1") as TextBox;这样的就代表第一行第二列的值,再去试试

你这样写不会出来值的因为你没有变成textbox,要这样写)
TextBox txt=this.GridView1.Rows[0].Cells[1].FindControl("TextBox1") as TextBox
string n=txt.Text;
这样就能取出来了,你可以试试

string n = ((TextBox)(this.gvPersonnel.Rows[0].Cells[1].Controls[0])).Text.Trim();

这样你拿一下

string n = ((TextBox)(this.GridView1.Rows[0].Cells[1])).Text.Trim();
不要FindControl