注册 登录
编程论坛 ASP.NET技术论坛

GridView数据更新问题

pietro 发布于 2006-11-19 22:52, 2335 次点击

代码如下:

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string userID = this.GridView1.DataKeys[e.RowIndex].Values[0].ToString();
string Name = ((TextBox)this.GridView1.Rows[e.RowIndex].FindControl("txtb1")).Text;
Response.Write(Name);
SqlConnection con = new SqlConnection("server=.;database=login;uid=sa;pwd=;");
con.Open();
SqlCommand cmd = new SqlCommand("update login set userName='" + Name + "' where userID='" + userID + "'", con);
cmd.ExecuteNonQuery();
this.GridView1.EditIndex = -1;
this.GridViewToBind();
}



我想实现GridView数据更新,可是老更新不过来,红色标出来的部分打印出来发现是未编辑前的数据,重新输入到文本框里的数据不能显示出来,那位知道是怎么回事???

6 回复
#2
pietro2006-11-21 16:39
不是吧   没有人能解决这个问题吗???
#3
湾仔沙2008-09-19 00:35
试下这个
在加载事件中写
if(!Ispostback)
{

    调用gridview绑定数据的方法;
}
#4
Xxibug2008-09-19 11:07
有点不明白,gridview从本地数据源如table读入数据,而数据源没更新的情况下。。。。
#5
zh5202008-09-22 22:27
提示: 作者被禁止或删除 内容自动屏蔽,只有管理员可见
#6
drychq2008-09-24 22:10
我 的  也  是这样 的 情况 。。。。
  不知道 楼主 解决 问题 没有 啊 。。。
有 的话 就说 一下 。。。

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int gvid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
            string username = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
            string userpwd = ((TextBox)(GridView1.Rows[e.RowIndex]).Cells[2].Controls[0]).Text.ToString().Trim();
            SqlConnection con3 = new SqlConnection(constr1);
            con3.Open();
            SqlCommand cmd = new SqlCommand("update admin set username='" + username + "',userpwd='" + userpwd + "' where userid='" + gvid + "'", con3);
            cmd.ExecuteNonQuery();
            con3.Close();
            data();
            GridView1.EditIndex = -1;
            
        }
#7
drychq2008-09-24 23:42
呵呵
  楼上的 湾仔沙
  说 正确 了
  。。。
就那样 。。。
1