📄 adduser.ascx.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 control_adduser : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//SqlConnection strcon = DB.createConnection();
//strcon.Open();
//SqlCommand cmd = new SqlCommand("select * from userclass ", strcon);
//SqlDataReader sdr = cmd.ExecuteReader();
//this.ddluserclass.DataSource = sdr;
//this.ddluserclass.DataValueField = "用户类型编号";
//this.ddluserclass.DataTextField = "用户类型";
//this.ddluserclass.DataBind();
this.bindtogridview();
}
}
protected void btnadduser_Click(object sender, EventArgs e)
{
string txtusername = this.txtusername.Text.ToString();
string txtuserpwd = this.txtuserpwd.Text.ToString();
//string ddluserclass = this.ddluserclass.Text.ToString();
SqlConnection con = DB.createConnection();
con.Open();
SqlCommand scd = new SqlCommand("insert into login(用户名,用户密码,用户类型编号)values('" + txtusername + "','" + txtuserpwd + "')",con);
scd.ExecuteNonQuery();
con.Close();
Response.Write("<script language=javascript>alert('您已经添加成功');location='adduser.aspx'</script>");
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void bindtogridview()
{
SqlConnection con = DB.createConnection();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from login", con);
DataSet ds = new DataSet();
sda.Fill(ds, "login");
this.GridView1.DataKeyNames = new string[] { "用户名" };
this.GridView1.DataSource = ds.Tables["login"];
this.GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
this.bindtogridview();
}
protected void ddluserclass_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -