GridView 编辑列的小问题

rooney321 2007-01-26 01:14:18
GridView1_RowUpdating 中
使用GridView1.Rows[e.RowIndex].Cells[0].Text; 为什么得到的值是原始值 而不是填入的新值???


代码如下:

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string a = this.GridView1.Rows[e.RowIndex].Cells[0].Text;
string b = this.GridView1.Rows[e.RowIndex].Cells[1].Text;
string c = this.GridView1.Rows[e.RowIndex].Cells[2].Text;
string d = this.GridView1.Rows[e.RowIndex].Cells[3].Text;
string e = this.GridView1.Rows[e.RowIndex].Cells[4].Text;
string constring;

string sql = "UPDATE XXX SET a='" + a + "', b='" + b + "', c='" + c + "', aprice='" + aprice + "' WHERE (servername='" + servername + "')";
constring = ConfigurationSettings.AppSettings["kkk"];
OleDbConnection scon = new OleDbConnection(constring);
OleDbCommand scmd = new OleDbCommand(sql, scon);
scon.Open();
scmd.ExecuteNonQuery();
this.GridView1.EditIndex = -1;
bindview(ViewState["sql"].ToString());

}
...全文
208 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
rockywu 2007-01-26
  • 打赏
  • 举报
回复
string a= ((Label)GridView1.Rows[e.RowIndex].Cells[11].FindControl("Label1")).Text;
找到你所要的控件值!GridView要先转模板列!
三个单引号??双引号里面是变量!!!!!
gsk99 2007-01-26
  • 打赏
  • 举报
回复
一个单引号+一个引号
'+"
baodijun 2007-01-26
  • 打赏
  • 举报
回复
string sql = "UPDATE XXX SET a='" + a + "', b='" + b + "', c='" + c + "', aprice='" + aprice + "' WHERE (servername='" + servername + "')";
有谁能告诉我,为什么都要三个单引号啊?一直搞不懂.郁闷。
gsk99 2007-01-26
  • 打赏
  • 举报
回复
如果出错 ,把出错的行注释调再测试
gsk99 2007-01-26
  • 打赏
  • 举报
回复
设断点 ,做测试
确定在那个cell下面肯定存在Textbox,比如是的n个
TextBox Tb1 = GridView1.Rows[e.RowIndex].Cells[n].Controls[0] as TextBox;//此行设断点,然后单步执行,看看哪个是你要 的值
string xx1 = Tb1.Text;
TextBox Tb2 = GridView1.Rows[e.RowIndex].Cells[n].Controls[1] as TextBox;
string xx2 = Tb2.Text;
TextBox Tb3 = GridView1.Rows[e.RowIndex].Cells[n].Controls[2] as TextBox;
string xx3 = Tb3.Text;
TextBox Tb4 = GridView1.Rows[e.RowIndex].Cells[n].Controls[3] as TextBox;
string xx4 = Tb4.Text;
TextBox Tb5 = GridView1.Rows[e.RowIndex].Cells[n].Controls[4] as TextBox;
string xx5 = Tb5.Text;
palts520 2007-01-26
  • 打赏
  • 举报
回复
e.NewValues
rooney321 2007-01-26
  • 打赏
  • 举报
回复
还是不行啊
获取的还是旧值
gsk99 2007-01-26
  • 打赏
  • 举报
回复

TextBox Tb1 = GridView1.Rows[e.RowIndex].Cells[0].Controls[0] as TextBox;
string xx = Tb1.Text;
rooney321 2007-01-26
  • 打赏
  • 举报
回复
附:SQL语句不用管 只想知道怎么获取新填入的值 用的GRIDVIEW自带的编辑功能
string sql = "UPDATE XXX SET a='" + a + "', b='" + b + "', c='" + c + "', aprice='" + aprice + "' WHERE (servername='" + servername + "')";

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧