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

📄 chakanly.aspx.cs

📁 在线商店
💻 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 User_chakanly : System.Web.UI.Page
{
 // private SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);
    DBClass db = new DBClass();
    private SqlConnection con = new SqlConnection();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            DandData();//绑定数据
        }
    }
    //为下拉列表添加选择项
    private void getListItem()
    {
        for (int i = 0; i < Convert.ToInt32(DBClass.Num); i++)
        {
            this.DropDownList1.Items.Add(Convert.ToString(Convert.ToInt32(i) + 1));
        }
    }
    //绑定数据
    public void DandData()
    {
        this.DropDownList1.Items.Clear();
        this.getListItem();   //向下拉列表中添加分页数

        int currPage = Convert.ToInt32(this.Label1.Text);

        con = db.GetConnection();
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = new SqlCommand("select * from liuyan order by id desc", con);
        DataSet ds = new DataSet();
        da.Fill(ds, "liuyan");

        PagedDataSource pds = new PagedDataSource(); //对用于分页的类的引用
        pds.DataSource = ds.Tables["liuyan"].DefaultView;//设置数据源(DataSet类型)
        pds.AllowPaging = true;

        pds.PageSize = 3;   //指定每页显示几条记录
        pds.CurrentPageIndex = currPage - 1;    //获取当前页索引后转到索引页

        if (currPage == 1)
        {
            this.Button1.Enabled = false;
            this.Button2.Enabled = false;
        }
        else
        {
            this.Button1.Enabled = true;
            this.Button2.Enabled = true;
        }

        if (currPage == pds.PageCount)
        {
            this.Button4.Enabled = false;
            this.Button3.Enabled = false;
        }
        else
        {
            this.Button4.Enabled = true;
            this.Button3.Enabled = true;
        }

        DBClass.Num = Convert.ToString(pds.PageCount);

        con.Open();
        SqlCommand cmd = new SqlCommand("select count(*) from liuyan", con);
        this.Label2.Text = "留言总记录数" + Convert.ToString((int)cmd.ExecuteScalar()) + "条";
        con.Close();

        this.ly.DataSource = pds;
        this.ly.DataBind();

    }

    //单击首页按钮事件
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.Label1.Text = "1";
        this.DandData();
        this.DropDownList1.Text = this.Label1.Text;
    }
    //单击上一页按钮事件
    protected void Button2_Click(object sender, EventArgs e)
    {
        this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text) - 1);
        this.DandData();
        this.DropDownList1.Text = this.Label1.Text;
    }
    //单击下一页按钮事件
    protected void Button3_Click(object sender, EventArgs e)
    {
        this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text) + 1);
        this.DandData();
        this.DropDownList1.Text = this.Label1.Text;
    }
    //单击尾页按钮事件
    protected void Button4_Click(object sender, EventArgs e)
    {
        this.Label1.Text = DBClass.Num;
        this.DandData();
        this.DropDownList1.Text = this.Label1.Text;
    }
    //下拉列表选中后转到指定的页
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.Label1.Text = this.DropDownList1.SelectedValue.ToString();
        this.DandData();
    }
    protected void ly_ItemCommand(object source, DataListCommandEventArgs e)
    {
        

        //回帖业务处理
        if (e.CommandName == "Reply")
        {
            int id = Convert.ToInt32(e.CommandArgument);
            if (Session["UID"] == null)
            {
                Response.Redirect("huifu.aspx?info=" + Server.HtmlEncode("对不起!只有管理员才有此权限!如果你是管理员请登陆!!") + "");
            }
            else
            {
                Response.Write("<script>alert('" + id + "')</script>");
                Response.Redirect("huifu2.aspx?ID=" + Server.HtmlEncode(id.ToString()) + "");
            }
        }
    }
}

⌨️ 快捷键说明

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