repeater控件分页

    #region 数据源绑定、分页
    /// <summary>
    /// 初始数据绑定
    /// </summary>
    public void dataBindToRepResouce(string condition)
    {
        if (condition == "")
        {
            condition = "1=1 order BY [ID] DESC";
        }
        else
        {
            condition += " order BY [ID] DESC";
        }
        int curpage = Convert.ToInt32(this.LA_Page.Text);
        PagedDataSource ps = new PagedDataSource();

        DataSet ds = Resouce.GetList(condition);//根据条件绑定资源,表示数据在内存中的缓存
        ps.DataSource = ds.Tables[0].DefaultView;//获取可能包括筛选视图或游标位置的表的自定义视图
        ps.AllowPaging = true;//允许分页
        ps.PageSize = 8;//每页8个
        ps.CurrentPageIndex = curpage - 1;//获取或设置当前页的索引
        this.LBT_Home.Enabled = true;//首页
        this.LBT_Pri.Enabled = true;//上一页要
        this.LBT_Next.Enabled = true;//下一页
        this.LBT_Tail.Enabled = true;//尾页

        if (curpage == 1)
        {
            this.LBT_Pri.Enabled = false;//上一页

        }
        if (curpage == ps.PageCount)//获取显示数据源中的所有项所需要的总页数
        {
            this.LBT_Next.Enabled = false;
        }

        this.lA_Count.Text = Convert.ToString(ds.Tables[0].Rows.Count);
        this.LA_PageCount.Text = Convert.ToString(ps.PageCount);
        this.RepResource.DataSource = ps;
        this.RepResource.DataBind();

        this.DropPage.Items.Clear();
        for (int i = 1; i <= Convert.ToInt32(this.LA_PageCount.Text); i++)
        {
          
            this.DropPage.Items.Add(new ListItem("第" + i.ToString() + "页", i.ToString()));
           
        }
        this.DropPage.SelectedIndex = Convert.ToInt32(this.LA_Page.Text) - 1;
    }
    /// <summary>
    /// 绑定类别信息
    /// </summary>
    public void dataBindToDDlType()
    {
        this.DDL_Type.DataSource = type.GetList("");
        this.DDL_Type.DataTextField = "Style";
        this.DDL_Type.DataValueField = "ID";
        this.DDL_Type.DataBind();
    }
    /// <summary>
    /// 绑定类别信息
    /// </summary>
    public void dataBindToSerchDDlType()
    {
        this.DDL_Stype.DataSource = type.GetList("");
        this.DDL_Stype.DataTextField = "Style";
        this.DDL_Stype.DataValueField = "ID";
        this.DDL_Stype.DataBind();
        this.DDL_Stype.Items.Insert(0, new ListItem("--请选择类别--", "0"));///添加默认选中项
    }
    /// <summary>
    /// 获取类别名
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    public string getType(object value)
    {
        string typeid = Convert.ToString(value);
        string ss;
        ss = type.getTypeName(typeid);
        return ss;
    }
    public string getType(string id)
    {
        string typeid = id;
        string ss;
        ss = type.getTypeName(typeid);
        return ss;
    }
    /// <summary>
    /// 首页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void LBT_Home_Click(object sender, EventArgs e)
    {
        this.LA_Page.Text = "1";
        querycondition = SearchCondition();
        this.dataBindToRepResouce(querycondition);
    }
    /// <summary>
    /// 上一页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void LBT_Pri_Click(object sender, EventArgs e)
    {
        this.LA_Page.Text = Convert.ToString(Convert.ToInt32(this.LA_Page.Text) - 1);
        querycondition = SearchCondition();
        this.dataBindToRepResouce(querycondition);
    }
    /// <summary>
    /// 下一页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void LBT_Next_Click(object sender, EventArgs e)
    {
        this.LA_Page.Text = Convert.ToString(Convert.ToInt32(this.LA_Page.Text) + 1);
        querycondition = SearchCondition();
        this.dataBindToRepResouce(querycondition);
    }
    /// <summary>
    /// 尾页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void LBT_Tail_Click(object sender, EventArgs e)
    {
        this.LA_Page.Text = this.LA_PageCount.Text;
        querycondition = SearchCondition();
        this.dataBindToRepResouce(querycondition);
    }
    /// <summary>
    /// 转至
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void DropPage_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.LA_Page.Text = this.DropPage.SelectedValue.ToString();
        querycondition = SearchCondition();
        this.dataBindToRepResouce(querycondition);
    }
    #endregion 数据源绑定、分页


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值