zoukankan      html  css  js  c++  java
  • datalist分页

     PagedDataSource pages;
        protected void Page_Load(object sender, EventArgs e)
        {
            DatalistBind();
        }

      private  void DatalistBind()
        {
            using (SqlConnection sqlcon = new SqlConnection("server=.;uid=sa;pwd=sa;database=xiaoxiDemo"))
           {
               int count = Convert.ToInt32(this.Label1.Text);
                SqlDataAdapter sqlda = new SqlDataAdapter("select * from xi",sqlcon);
                DataSet dt = new DataSet();
                sqlda.Fill(dt, "xi");
                pages = new PagedDataSource();
                pages.DataSource = dt.Tables[0].DefaultView;
                pages.AllowPaging = true;
                pages.PageSize =6;
                pages.CurrentPageIndex = count- 1;
                this.DataList1.DataSource = pages;
                this.DataList1.DataBind();
                this.Button2.Enabled = true;
                this.Button3.Enabled = true;
                if (count == 1)
                {
                    this.Button2.Enabled=false;
                }
                if (count==pages.Count)
                {
                    this.Button3.Enabled = false;
                }
            }
           
        }
        //上一页
        protected void Button2_Click(object sender, EventArgs e)
        {
            this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text)- 1);
            DatalistBind();
        }
        //下一页
        protected void Button3_Click(object sender, EventArgs e)
        {
            this.Label1.Text = Convert.ToString(Convert.ToInt32(this.Label1.Text)+1);
            DatalistBind();
        }
        //删除
        protected void LinkButton1_Command(object sender, CommandEventArgs e)
        {
            using (SqlConnection sqlcon = new SqlConnection("server=.;uid=sa;pwd=sa;database=xiaoxiDemo"))
            {
                sqlcon.Open();
                SqlCommand sqlcmds = new SqlCommand("delete from xi where xi_id="+e.CommandArgument+"",sqlcon);
                sqlcmds.ExecuteNonQuery();
                sqlcon.Close();
            }
        }
        //首页
        protected void Button1_Click(object sender, EventArgs e)
        {
            this.Label1.Text = "1";
            DatalistBind();
        }

        //尾页
        protected void Button4_Click(object sender, EventArgs e)
        {
            this.Label1.Text = pages.Count.ToString();
            DatalistBind();
        }

  • 相关阅读:
    Python_字典
    Python_字符串方法
    跳转到新页面,加载过程中加入等待过渡的动态效果
    web项目引入第三方jar包,编译时找不到的问题与及解决方案
    Eclipse的debug按钮介绍
    什么是TCP粘包?怎么解决TCP粘包问题?UDP协议存在粘包问题吗?
    使用Java编写TCP协议发送和接收数据接口
    UUID生成唯一的16位随机数
    如何在父页面中操作/获取iframe页面中的元素?这个小问题折腾了我快半个小时,所以记下来吧!
    如何接收APP的请求,并且如何以json字符串的格式封装响应的数据,然后发送回APP
  • 原文地址:https://www.cnblogs.com/freexiaoyu/p/1259586.html
Copyright © 2011-2022 走看看