在Asp.net中继器控制中进行分页和排序

时间:2013-07-26 10:56:26

标签: asp.net xml repeater

在下面的代码中,我试图在转发器顶部显示最新记录。我还想在repeater中包含分页。页面在页面上成功完成,但是当我在转发器中进行排序时我遇到了麻烦。所以我的问题是如何在转发器中进行排序和分页?

我的代码:

private void Get_Data()
    {

        String File = Server.MapPath("~/Data/BlogContent.xml");
        DataSet ds = new DataSet();

        ds.ReadXml(File);

        DataView dv = new DataView(ds.Tables[0]);
        dv.Sort = "id DESC";
        DataTable dt = dv.Table;
        ViewState.Add("Mytable", dt);

    }
    private void Bind_Data(int take, int pageSize)
    {
        PagedDataSource page = new PagedDataSource();
        page.AllowCustomPaging = true;
        page.AllowPaging = true;
        DataTable dtv = (DataTable)ViewState["Mytable"];
        DataView dv = new DataView();
        dv = dtv.DefaultView;
        dv.Sort = "id ASC";
        dv.RowFilter = "id>=" + pageSize + " AND " + "id<=" + take;
        page.DataSource = dv;
        page.PageSize = psize;
        Repeater1.DataSource = page;
        Repeater1.DataBind();

        if (!IsPostBack)
        {
            int rowcount = dtv.Rows.Count;
            CreatePagingControl(rowcount);
        }

    } 

2 个答案:

答案 0 :(得分:0)

For paging Check this.Here是paging.link

的完整示例

paging and sorting

答案 1 :(得分:0)

**阅读文章: asp.net中的Repeater控件中的自定义分页(C#,VB)** http://www.webcodeexpert.com/2013/05/custom-paging-in-repeater-control-in.html