📄 adminusernamefind.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 adminusernamefind : System.Web.UI.Page
{
SqlCommand cmd, cmd1;
SqlConnection cn;
SqlDataReader dr;
SqlDataAdapter da, da1;
DataSet ds = new DataSet();
DataSet ds1 = new DataSet();
string strsql1, strsql2;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["adminname"] == null)
{
Response.Redirect("index.aspx");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.IsValid)
{
cn = sqldata.createcon();
cn.Open();
strsql1 = "select * from users where username='" + this.txtuserid.Text + "'";
da = new SqlDataAdapter(strsql1, cn);
da.Fill(ds1);
this.mydatagrid3.DataSource = ds1.Tables[(0)].DefaultView;
this.mydatagrid3.DataBind();
if (this.mydatagrid3.Items.Count == 0)
{
this.Panel1.Visible = false;
this.labmessage.Text = "对不起?要找的" + this.txtuserid.Text.ToString() + "内容还没有找到";
this.HyperLink1.Visible = true;
}
else
{
this.Panel1.Visible = true;
this.HyperLink1.Visible = true;
this.labmessage.Text = "恭喜!要找的" + this.txtuserid.Text.ToString() + "内容找到了"; ;
}
}
}
protected void mydatagrid3_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#d3d3d3'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
((LinkButton)(e.Item.Cells[16].Controls[0])).Attributes.Add("onclick", "return confirm('您确认要删除吗?');");
}
}
protected void mydatagrid3_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
this.mydatagrid3.CurrentPageIndex = e.NewPageIndex;
this.mydatagrid3 .DataBind ();
}
protected void mydatagrid3_DeleteCommand(object source, DataGridCommandEventArgs e)
{
cn = sqldata.createcon();
cn.Open();
strsql1 = "select * from users where userid='" + this.txtuserid.Text + "'";
da = new SqlDataAdapter(strsql1, cn);
da.Fill(ds1);
this.mydatagrid3.DataKeyField = "userid";
this.mydatagrid3.DataSource = ds1.Tables[(0)].DefaultView;
this.mydatagrid3.DataBind();
int id = Convert.ToInt32(this.mydatagrid3.DataKeys[e.Item.ItemIndex].ToString());
cn = sqldata.createcon();
cn.Open();
strsql1 = "delete from users where userid='" + id + "'";
cmd1 = new SqlCommand(strsql1, cn);
cmd1.ExecuteNonQuery();
this.mydatagrid3.DataBind();
this.labmessage.Text = "删除成功";
this.HyperLink1.Visible = true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -