gridview 更新问题,急呀,大家来帮忙

来源:百度知道 编辑:UC知道 时间:2024/06/20 06:36:58
我点了更新后,没有异常,但是我输入的新值却取不出来,其他的地方都没有错,就是我输入的值取不出来。也就是说,我输入什么还是更新不了。打印出得值是他本来有的。

代码如下:
String ID = GridView1.DataKeys[e.RowIndex].Value.ToString();

string StudentID = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim();

string Name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
string Sex = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
string Telephone = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
string strup = "update Student set StudentID='" + StudentID
+ "',Name='" + Name + "',Sex='" + Sex + "',Telephone='" + Telephone + "' where StudentID=" + ID + "";
SqlConnection sqlcon = new SqlConnection("server=.;uid=sa;pwd=;dat

你把你的string strup = "update Student set StudentID='" + StudentID
+ "',Name='" + Name + "',Sex='" + Sex + "',Telephone='" + Telephone + "' where StudentID=" + ID + "";
换成下面这句话试试:

string strup = "update Student set StudentID='" + StudentID
+ "',Name='" + Name + "',Sex='" + Sex + "',Telephone='" + Telephone + "' where StudentID='" + ID + "'";

])).Text.ToString()。。。 Text已经是string了还ToString干什么啊

你加个断点 跟踪调试下

string Name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();

你把这个拆开,用TextBox tb=加上后面那段 这样,加个断点看下tb的值。另外不知道你这些textbox都放在哪个模块了,试试看Cells[].FindControl[""]如何