判断文本框内容是否改变
更新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。但是应该怎么改呢?