📄 addclient.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_addclient : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.bindtogridview();
}
//if (Convert.ToString(Session["username"]) == "")
//{
// Response.Write("<script language=javascript>alert('请登录');location='../login.aspx'</script>");
// return;
//}
}
protected void btnaddclient_Click(object sender, EventArgs e)
{
string txtclientnum = this.txtclientnun.Text.ToString();
string txtclientname = this.txtclientname.Text.ToString();
string txtconpeople = this.txtconpeople.Text.ToString();
string txtphoto= this.txtphoto.Text.ToString();
string txtaddress = this.txtaddress.Text.ToString();
SqlConnection strcon = DB.createConnection();
//new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
strcon.Open();
SqlCommand scd = new SqlCommand("insert into client(客户编号,客户名称,联系人,联系电话,联系地址)values('" + txtclientnum + "','" + txtclientname + "','" + txtconpeople + "','" + txtphoto + "','" + txtaddress + "')", strcon);
scd.ExecuteNonQuery();
strcon.Close();
Response.Write("<script language=javascript>alert('您已经添加成功');location='addclient.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 client", con);
DataSet ds = new DataSet();
sda.Fill(ds, "client");
this.GridView1.DataKeyNames = new string[] {"客户编号"};
this.GridView1.DataSource = ds.Tables["client"];
this.GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
this.bindtogridview();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -