📄 wldwwh.aspx.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
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;
public partial class spwh : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//默认显示商品资料的第一页
bindgrig();
}
}
void bindgrig()
{
SqlConnection Conn;
// 设置数据库连接
String strConn = ConfigurationManager.AppSettings["conn"];
Conn = new SqlConnection(strConn);
//从数据库取查询结果
SqlDataAdapter Cmd = new SqlDataAdapter("select 往来单位编号,往来单位名称,地址,电话 from 往来单位 where 往来单位名称 like '%" + this.TextBox1.Text + "%' order by 往来单位编号", Conn);
DataSet Ds = new DataSet();
Cmd.Fill(Ds, "往来单位资料");
//指定数据源
GridView1.DataSource = new DataView(Ds.Tables[0]);
//数据绑定
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
//查询符合条件商品,默认第一页
GridView1.PageIndex = 0;
bindgrig();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//改变显示页面
GridView1.PageIndex = e.NewPageIndex;
bindgrig();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
//设置行编辑状态
GridView1.EditIndex = e.NewEditIndex;
bindgrig();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//设置数据库连接
SqlConnection Conn;
String strConn = ConfigurationManager.AppSettings["conn"];
Conn = new SqlConnection(strConn);
Conn.Open();
//删除行处理
String sql = "delete from 往来单位 where 往来单位编号='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
SqlCommand Comm = new SqlCommand(sql, Conn);
Comm.ExecuteNonQuery();
Conn.Close();
GridView1.EditIndex = -1;
bindgrig();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//设置数据库连接
SqlConnection Conn;
String strConn = ConfigurationManager.AppSettings["conn"];
Conn = new SqlConnection(strConn);
Conn.Open();
//提交行修改
String sql = "update 往来单位 set 往来单位名称='" + ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1")).Text + "',地址='" + ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox3")).Text + "',电话='" + ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox4")).Text + "' where 往来单位编号='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
SqlCommand Comm = new SqlCommand(sql, Conn);
Comm.ExecuteNonQuery();
Conn.Close();
GridView1.EditIndex = -1;
bindgrig();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//行编辑状态取消
GridView1.EditIndex = -1;
bindgrig();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -