📄 useredit.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace car1
{
/// <summary>
/// useredit 的摘要说明。
/// </summary>
public class useredit : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label3;
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
usereditBind();// 在此处放置用户代码以初始化页面
}
private void usereditBind()
{
//初始化姓名,用户名,联系方式信息
string U_id=Request["id"].ToString();
string SqlConn=System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
SqlConnection Conn=new SqlConnection(SqlConn);
Conn.Open();
string SqlStr1="select name,username,mobile,userrule from [user] where id='"+U_id+"'";
SqlCommand Comm1=new SqlCommand(SqlStr1,Conn);
SqlDataReader read1=Comm1.ExecuteReader();
if(read1.Read())
{
this.Label1.Text=read1["name"].ToString();
this.Label2.Text=read1["username"].ToString();
this.TextBox1.Text=read1["mobile"].ToString();
read1.Close();
}
//初始化单位信息
string SqlStr2="select type from [bumen]";
SqlDataAdapter myadapter =new SqlDataAdapter(SqlStr2,Conn);
DataSet ds=new DataSet();
myadapter.Fill(ds,"bumen");
this.DropDownList1.DataSource=ds;
this.DropDownList1.DataTextField="type";
this.DropDownList1.DataValueField="type";
this.DropDownList1.DataBind();
this.DropDownList1.Items.Add("--单位--");
this.DropDownList1.Items[this.DropDownList1.Items.Count-1].Value="";
this.DropDownList1.SelectedIndex=this.DropDownList1.Items.Count - 1;
//初始化用户权限信息
this.DropDownList2.Items.Add(new ListItem("普通用户","1"));
this.DropDownList2.Items.Add(new ListItem("超级用户","2"));
//关闭连接
Conn.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
//修改用户信息
private void Button1_Click(object sender, System.EventArgs e)
{
string B_id=Request["id"].ToString();
string B_name=this.Label1.Text;
string B_username=this.Label2.Text;
string B_part=this.DropDownList1.SelectedItem.Text;
string B_mobile=this.TextBox1.Text;
string B_userrule=this.DropDownList2.SelectedItem.Text;
string SqlConn=System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
SqlConnection Conn=new SqlConnection(SqlConn);
Conn.Open();
string SqlStr3="update [user] set name='"+B_name+"',username='"+B_username+"',part='"+B_part+"',mobile='"+B_mobile+"',userrule='"+B_userrule+"' where id='"+B_id+"'";
SqlCommand Comm2=new SqlCommand(SqlStr3,Conn);
Comm2.ExecuteNonQuery();
this.Label3.Text="修改用户信息成功,请关闭窗口!";
this.TextBox1.Text="";
Conn.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -