📄 popedommanage.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
public partial class UserInfo_PopedomManage : System.Web.UI.Page
{
private string userId;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Params["userid"] == null)
{
}
else
{
userId = Request.Params["userid"].ToString();
}
}
protected void Btnsave_Click(object sender, EventArgs e)
{
StringBuilder strSQL = new StringBuilder();
using (SqlConnection conn = DataAccess.CreateConnection())
{
conn.Close();
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.Parameters.Add("@USERID", SqlDbType.VarChar);//设定参数名
cmd.Parameters["@USERID"].Value = userId;//为参数赋值
strSQL.Append(" Delete from t_Popedom where USERID = @USERID ");//追加删除用户Sql语句
//从GridView控件中选出checkboxes控件
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;
if (isChecked)
{
//如果checkboxes被选中,追加insert语句添加用户权限
strSQL.Append(" Insert into t_Popedom (CLASSID, USERID) values (" + GridView1.Rows[i].Cells[0].Text + ", @USERID) ");
}
}
cmd.CommandText = strSQL.ToString();
cmd.CommandTimeout = 300;
//启动事务处理
SqlTransaction sqlTran = conn.BeginTransaction();
cmd.Transaction = sqlTran;
try
{
cmd.ExecuteNonQuery();
//提交事务
sqlTran.Commit();
}
catch (Exception ex)
{
//事务回滚
sqlTran.Rollback();
//elMsg.InnerHtml = ex.ToString();//错误提示
}
finally
{
sqlTran.Dispose();//结束事务,释放资源
conn.Close();//关闭数据库连接
}
}
}
protected void Btnback_Click(object sender, EventArgs e)
{
Response.Redirect("UserManage.aspx");
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex != -1)
{
string sql = "select * from t_Popedom where CLASSID=" + e.Row.Cells[0].Text + " and USERID=@USERID";
SqlConnection con = DataAccess.CreateConnection();
SqlCommand com = new SqlCommand(sql, con);
com.Parameters.AddWithValue("@USERID", userId);
con.Open();
SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
CheckBox chk = (CheckBox)e.Row.Cells[4].FindControl("chkSelect");
chk.Checked = true;//CheckBox 被选中
}
else
{
CheckBox chk = (CheckBox)e.Row.Cells[4].FindControl("chkSelect");
chk.Checked = false;//CheckBox 未被选中
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -