📄 editadmin.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;
public partial class editadmin : System.Web.UI.Page
{
SqlConnection cn;
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Convert.ToString(Session["role"]) == "普通用户")
{
Response.Write("<script language='javascript'>alert('非常抱歉!您不是"管理员",不能进入该页面!^_^');window.location.href='Default.aspx'</script>");
}
this.databinduserinfo();
}
}
public static string pagecount;
private void databinduserinfo()
{
string admin="管理员";
int countpage = Convert.ToInt32(this.Labelye.Text);
cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cn"]);
cn.Open();
SqlDataAdapter da = new SqlDataAdapter("select* from userinfo where role='"+admin+"' order by id desc", cn);
da.Fill(ds, "Result");
System.Web.UI.WebControls.PagedDataSource ps = new PagedDataSource();
ps.DataSource = ds.Tables["Result"].DefaultView;
ps.AllowPaging = true;
ps.PageSize = 12;
ps.CurrentPageIndex = countpage - 1;
this.lblPageCount.Text = Convert.ToString(ps.PageCount);
this.Button2.Enabled = true;
this.Button3.Enabled = true;
if (countpage == 1)
{
this.Button2.Enabled = false;
}
if (countpage == ps.PageCount)
{
this.Button3.Enabled = false;
}
this.gvadmininfo.DataSource = ps;
this.gvadmininfo.DataBind();
SqlCommand cmd = new SqlCommand("select count(*) from userinfo where role='" + admin + "'", cn);
this.lblRecordCount.Text = Convert.ToString(cmd.ExecuteScalar());
pagecount = Convert.ToString(ps.PageCount);
cn.Close();
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
foreach (GridViewRow gr in gvadmininfo.Rows)
{
CheckBox chk = (CheckBox)gr.Cells[6].FindControl("itemchk");
if (!chk.Checked)
{
chk.Checked = true;
}
else
{
chk.Checked = false;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.Labelye.Text = "1";
this.databinduserinfo();
}
protected void Button2_Click(object sender, EventArgs e)
{
this.Labelye.Text = Convert.ToString(Convert.ToInt32(this.Labelye.Text) - 1);
this.databinduserinfo();
}
protected void Button3_Click(object sender, EventArgs e)
{
this.Labelye.Text = Convert.ToString(Convert.ToInt32(this.Labelye.Text) + 1);
this.databinduserinfo();
}
protected void Button4_Click(object sender, EventArgs e)
{
this.Labelye.Text =pagecount;
this.databinduserinfo();
}
protected void Btndel_Click(object sender, EventArgs e)
{
try
{
int intCount = this.gvadmininfo.Rows.Count;
for (int i = 0; i < intCount; i++)
{
CheckBox CheckSingle = this.gvadmininfo.Rows[i].Cells[6].FindControl("itemchk") as CheckBox;
if (CheckSingle.Checked)
{
int id = Convert.ToInt32(this.gvadmininfo.Rows[i].Cells[0].Text);
cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cn"]);
cn.Open();
SqlCommand cmd = new SqlCommand("delete from userinfo where id=" + id, cn);
cmd.ExecuteNonQuery();
this.Labmessage.Text = "删除所选的管理员成功";
}
}
this.databinduserinfo();
}
catch
{
this.Labmessage.Text = "服务器忙,请一会在试!";
}
finally
{
cn.Close();
}
}
protected void gvadmininfo_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#ffffff';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
this.Btndel.Attributes.Add("onclick", "return confirm('您确认要删除所选的会员吗?');");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -