way_list.aspx.cs

来自「网站开发与实例,提供完整的电子商务网站源代码。」· CS 代码 · 共 79 行

CS
79
字号
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_Way_list : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.bind();
        }
    }
    public void bind()
    {
        SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
        strcon.Open();
        SqlDataAdapter sda = new SqlDataAdapter("select * from tb_Way order by id desc", strcon);
        DataSet ds = new DataSet();
        sda.Fill(ds,"tb_Way");
        this.GridView1.DataSource=ds.Tables["tb_Way"];
        this.GridView1.DataKeyNames = new string[] {"id"};
        this.GridView1.DataBind();
    }
    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('确定删除吗?')");
        }
    }
    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_Way where id="+id,strcon);
        scd.ExecuteNonQuery();
        this.bind();
        strcon.Close();
    }
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        string id=this.GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
        SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
        strcon.Open();
        SqlCommand scd = new SqlCommand("select Auditing from tb_way where id="+id,strcon);
        string Auditing = Convert.ToString(scd.ExecuteScalar());
        if (Auditing == "0")
        {
            Auditing = "1";
        }
        else
        {
            Auditing = "0";
        }
        scd.CommandText = "update tb_way set Auditing="+Auditing+" where id="+id;
        scd.ExecuteNonQuery();
        this.bind();
        strcon.Close();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?