日期:2014-05-17 浏览次数:20508 次
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { int index = e.RowIndex;//当前选择行索引值 string roomno = GridView1.DataKeys[index].Value.ToString();//获取主键房间号 string roomtype = ((TextBox)(GridView1.Rows[index].Cells[4].Controls[0])).Text.Trim(); string roomstatu = ((TextBox)(GridView1.Rows[index].Cells[5].Controls[0])).Text.Trim(); string unitprice = ((TextBox)(GridView1.Rows[index].Cells[6].Controls[0])).Text.Trim(); string sql = "update room set roomtype="+roomtype+",roomstatu="+roomstatu+",unitprice="+unitprice+"";//更新语句 SqlConnection conn = new SqlConnection(strCon); conn.Open(); SqlCommand comm = new SqlCommand(sql, conn); int ret = comm.ExecuteNonQuery(); if (ret>0) { //更新成功 } else { //更新失败 } GridView1.EditIndex = -1; DataBind(); } catch (Exception ex) { throw; } } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int index = e.RowIndex; string roomno = GridView1.DataKeys[index].Value.ToString(); //rxxx ro = new rxxx(); //ro.roomno = roomno; //ro.Del(); string sql = "delete from room where roomno="+roomno+"";//更新语句 SqlConnection conn = new SqlConnection(strCon); conn.Open(); SqlCommand comm = new SqlCommand(sql, conn); conn.Close(); DataBind(); }