?? userlist.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.Configuration ;
using System.Data .SqlClient ;
namespace MMS
{
/// <summary>
/// userlist 的摘要說明。
/// </summary>
public class userlist : System.Web.UI.Page
{
protected System.Web.UI.WebControls.HyperLink HyperLink2;
protected System.Web.UI.WebControls.Button btn_search;
protected System.Web.UI.WebControls.TextBox tbx_uid;
protected System.Web.UI.WebControls.HyperLink hlk_bookmanage;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.DataGrid dgd_userlist;
public void Page_Load(object sender, System.EventArgs e)
{if(!IsPostBack) BindGrid();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:該調(diào)用是 ASP.NET Web 窗體設(shè)計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.btn_search.Click += new System.EventHandler(this.btn_search_Click);
this.dgd_userlist.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
public void BindGrid()
{ //從文件Web.config中讀取連接字符串
string strconn= ConfigurationSettings.AppSettings["dsn"];
//連接本地計算機的MMS數(shù)據(jù)庫
SqlConnection cn= new SqlConnection (strconn);
//創(chuàng)建SqlDataAdapter對象,調(diào)用存儲過程
SqlDataAdapter da=new SqlDataAdapter ("userlist",cn);
//創(chuàng)建并填充DataSet
DataSet ds=new DataSet ();
da.Fill (ds);
dgd_userlist.DataSource =ds;
dgd_userlist.DataBind ();
cn.Close ();
}
public void DataGrid_Edit(Object sender,DataGridCommandEventArgs E)
{
dgd_userlist.EditItemIndex =(int)E.Item .ItemIndex ;
BindGrid();
}
public void DataGrid_Cancel(Object sender,DataGridCommandEventArgs E)
{
dgd_userlist.EditItemIndex =-1;
BindGrid();
}
public void DataGrid_Update(Object sender,DataGridCommandEventArgs E)
{ //從文件Web.config中讀取連接字符串
string strconn= ConfigurationSettings.AppSettings["dsn"];
//連接本地計算機的MMS數(shù)據(jù)庫
SqlConnection cn= new SqlConnection (strconn);
cn.Open ();
SqlCommand cm=new SqlCommand ("usermodifyForAdmin",cn);
//將命令類型轉(zhuǎn)為存儲類型
cm.CommandType =CommandType.StoredProcedure ;
cm.Parameters .Add ("@UID",SqlDbType.VarChar);
cm.Parameters .Add (new SqlParameter ("@UPower",SqlDbType.Int));
//從DateGrid中取得更新內(nèi)容,Cells [0]為UID列
string uidvalue=E.Item.Cells[1].Text .ToString ();
cm.Parameters ["@UID"].Value =uidvalue;
//從DateGrid中取得更新內(nèi)容
string upowervalue=((DropDownList)E.Item.FindControl ("ddl_upower")).SelectedItem.Value .ToString ();
cm.Parameters ["@UPower"].Value =Convert.ToInt16 (upowervalue);
cm.ExecuteNonQuery ();
dgd_userlist.EditItemIndex =-1;
BindGrid();
}
public void DataGrid_Delete(Object sender,DataGridCommandEventArgs E)
{
//從文件Web.config中讀取連接字符串
string strconn= ConfigurationSettings.AppSettings["dsn"];
//連接本地計算機的MMS數(shù)據(jù)庫
SqlConnection cn= new SqlConnection (strconn);
cn.Open ();
SqlCommand cm=new SqlCommand ("userdelete",cn);
cm.CommandType =CommandType.StoredProcedure ;
cm.Parameters .Add ("@UID",SqlDbType.VarChar );
//從DateGrid中取得更新內(nèi)容
//Cells [0]為UID列
string uidvalue=E.Item.Cells [0].Text .ToString ();
cm.Parameters ["@UID"].Value =uidvalue;
cm.ExecuteNonQuery ();
dgd_userlist.EditItemIndex =-1;
BindGrid();
}
public void DataGrid_Page(Object sender,DataGridPageChangedEventArgs E)
{
dgd_userlist.CurrentPageIndex =E.NewPageIndex ;
BindGrid();
}
private void btn_search_Click(object sender, System.EventArgs e)
{
string varuid=tbx_uid.Text .ToString ();
Response.Redirect ("userdetail.aspx?uid="+varuid);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -