⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.aspx.cs

📁 数据绑定采用GridView控件
💻 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.OleDb;
public partial class admin_main : System.Web.UI.Page
{
    OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
    DataBase db = new DataBase();
    protected void Page_Load(object sender, EventArgs e)
    {

        if(!this.Page.IsPostBack)
        {
            this.ShowInfo();
        }
    }
    private void ShowInfo() 
    {
        string str = "select * from message";
        OleDbDataAdapter da = new OleDbDataAdapter(str,conn);
        DataSet ds = new DataSet();
        da.Fill(ds,"a");
        this.GridView1.DataSource = ds.Tables["a"].DefaultView;
        this.GridView1.DataKeyNames = new string[] { "id" };
        this.GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        this.ShowInfo();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string sql = "select * from message";
        OleDbDataAdapter da = new OleDbDataAdapter(sql,conn);
        OleDbCommandBuilder oc = new OleDbCommandBuilder(da);
        DataSet ds = new DataSet();
        da.Fill(ds,"b");
        DataRow row = ds.Tables["b"].Rows[e.RowIndex];
        row.Delete();
        da.Update(ds,"b");
        this.ShowInfo();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if(e.Row.RowType==DataControlRowType.DataRow)
        {
            if (e.Row.Cells[4].Text.Trim() == "0")
            {
                e.Row.Cells[4].Text = "<font color=red>隐藏</font>";
            }
            else 
            {
                e.Row.Cells[4].Text = "公开";
            }
            if (e.Row.Cells[5].Text.Trim() == "0")
            {
                e.Row.Cells[5].Text = "<font color=red>新留言</font>";
            }
            else 
            {
                e.Row.Cells[5].Text = "已回复";
            }
            ((LinkButton)(e.Row.Cells[6].Controls[0])).Attributes.Add("onclick","return confirm('确定要删除吗?')");
        }
    }
}

⌨️ 快捷键说明

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