?? 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 + -