首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

判断文本框内容是不是改变

2012-12-15 
判断文本框内容是否改变更新gridview的权限和密码两项:protected void GridView1_RowUpdating(object send

判断文本框内容是否改变
更新gridview的权限和密码两项:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  {
  string id = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
  string pwd = Convert.ToString(((TextBox)GridView1.Rows[e.RowIndex].FindControl("password")).Text);
  string per = Convert.ToString(((DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlPermi")).SelectedValue);

  string connStr = "Data Source=SUNNING-PC;Initial Catalog=HX;Integrated Security=True";
  string SqlStr = "update tab_user set password='" + pwd + "',permission='" + per + "' where user_id=" + id;

  try
  {
  SqlConnection conn = new SqlConnection(connStr);
  if (conn.State.ToString() == "Closed") conn.Open();
  SqlCommand comm = new SqlCommand(SqlStr, conn);
  comm.ExecuteNonQuery();
  comm.Dispose();
  if (conn.State.ToString() == "Open") conn.Close();

  GridView1.EditIndex = -1;
  GridViewBind();
  }
  catch (Exception ex)
  {
  Response.Write("数据库错误,错误原因:" + ex.Message);
  Response.End();
  }
  }

下面这句总是提示System.NullReferenceException: 未将对象引用设置到对象的实例:
string pwd = Convert.ToString(((TextBox)GridView1.Rows[e.RowIndex].FindControl("password")).Text);

查了一下应该原因是值是NULL。但是应该怎么改呢?

热点排行