?? user_list.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 System.Data.SqlClient;
public partial class Manage_User_list : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.bind();
}
}
public void bind()
{
SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
strcon.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from tb_User order by id desc", strcon);
DataSet ds = new DataSet();
sda.Fill(ds, "tb_User");
this.GridView1.DataSource = ds.Tables["tb_User"];
this.GridView1.DataKeyNames = new string[] { "id" };
this.GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
this.bind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
strcon.Open();
SqlCommand scd = new SqlCommand("delete from tb_User where id=" + id, strcon);
scd.ExecuteNonQuery();
this.bind();
strcon.Close();
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
strcon.Open();
string id = this.GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
SqlCommand scd = new SqlCommand("select Auditing from tb_User where id=" + id, strcon);
string Auditing = Convert.ToString(scd.ExecuteScalar());
if (Auditing == "0")
{
Auditing = "1";
}
else
{
Auditing = "0";
}
scd.CommandText = "update tb_User set Auditing=" + Auditing + " where id=" + id;
scd.ExecuteNonQuery();
this.bind();
strcon.Close();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[4].Text == "0")
{
e.Row.Cells[4].Text = "未審核";
}
else
{
e.Row.Cells[4].Text = "<font color=red>已審核</font>";
}
((LinkButton)(e.Row.Cells[6].Controls[0])).Attributes.Add("onclick", "return confirm('確定刪除嗎?')");
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -