?? editusers.aspx.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 SMS;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
OPDataBase op = new OPDataBase();
static string Sql = "select UserName,Power,Password ,Sex from Users";
protected void Page_Load(object sender, EventArgs e)
{ //SqlConnection conn=new SqlConnection (op .getConnection ());
// conn.Open();
if (!IsPostBack)
{
bind();
}
GridView1.Attributes.Add("style", "table-layout:fixed");
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
GridView1.PageIndex = e.NewPageIndex;
bind();
}
catch { }
}
public void bind()
{
op.BinData(Sql , GridView1);
GridView1 .DataKeyNames =new string[] {"UserName"};
}
protected void Button1_Click(object sender, EventArgs e)
{
Sql = "select *from Users where "+DropDownList1.SelectedValue .ToString ()+"='"+TextBox_Infor .Text .Trim ()+"'";
bind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string sql = "update Users set UserName='" +
((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.ToString().Trim() + "',Password='" +
((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim () + "',Power='" +
((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "' where UserName='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
op.BindCommand(sql);
GridView1.EditIndex = -1;
bind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string str = "delete from Users where UserName='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
op.BindCommand(str);
bind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠標經過時,行背景色變
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
//鼠標移出時,行背景色變
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
//((ImageButton)(e.Row.Cells[9].Controls[0])).Attributes.Add("onclick", "return confirm('你確認要刪除嗎?')");
//如果是綁定數據行 //清清月兒http://blog.csdn.net/21aspnet
}
}
protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
{
Sql = "select UserName,Power,Password ,Sex from Users";
op.BinData(Sql , GridView1);
GridView1.DataKeyNames = new string[] { "UserName" };
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -