【发布时间】:2014-02-09 18:21:52
【问题描述】:
这里的代码有什么问题...我正在尝试通过编辑、更新、取消命令字段按钮更新在网格视图的一行中获取的值。
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Label lblid = (Label)GridView1.Rows[e.RowIndex].FindControl("Elblid");
TextBox txtuser = (TextBox)GridView1.Rows[e.RowIndex].FindControl("EtxtUserName");
TextBox txtpass = (TextBox)GridView1.Rows[e.RowIndex].FindControl("EPassword");
if (lblid.Text != "" || lblid.Text != null)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["con"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Update Login set UserName='" + txtuser.Text + "',Password='" + txtpass.Text + "' Where Id=" + lblid.Text, con);
cmd.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
FillGrid();
}
这是抛出的错误:
PS:当页面指令中的事件验证设置为 false 时。这个错误消失了,但代码没有做任何事情。
【问题讨论】:
标签: c# asp.net .net gridview updating