How to get radlistview items if you use paging

回眸只為那壹抹淺笑 提交于 2019-12-12 05:36:51

问题


I'm using radlistview in my asp.net project . The problem that when I have to get all items of radlistview it return only items of the current page.

Example :

radlistview2.Items.ToList();

Output : I got only 10 elements which are in the first page

My Question is :

How To get all items in radlistview ???


回答1:


Please try with the below code snippet.

ASPX

<telerik:RadListView ID="RadListView1" runat="server" OnNeedDataSource="RadListView1_NeedDataSource" AllowPaging="true" PageSize="2">
            <ItemTemplate>
                <%# Eval("ID") %>
            </ItemTemplate>
        </telerik:RadListView>
        <telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="RadListView1"
            PageSize="2">
            <Fields>
                <telerik:RadDataPagerButtonField FieldType="FirstPrev"></telerik:RadDataPagerButtonField>
                <telerik:RadDataPagerButtonField FieldType="Numeric"></telerik:RadDataPagerButtonField>
                <telerik:RadDataPagerButtonField FieldType="NextLast"></telerik:RadDataPagerButtonField>
            </Fields>
        </telerik:RadDataPager>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

ASPX.CS

protected void RadListView1_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e)
{
    dynamic data1 = new[] {
           new { ID = 1, Name ="Name_1",Customdate = DateTime.Now},
           new { ID = 2, Name = "Name_2",Customdate = DateTime.Now},
           new { ID = 3, Name = "Name_3",Customdate = DateTime.Now},
           new { ID = 4, Name = "Name_4",Customdate = DateTime.Now},
           new { ID = 5, Name = "Name_5",Customdate = DateTime.Now}
       };
    RadListView1.DataSource = data1;
}
protected void Button1_Click(object sender, EventArgs e)
{
    int i = RadListView1.Items.Count();

    RadListView1.AllowPaging = false;
    RadListView1.Rebind();

    int j = RadListView1.Items.Count();
    //Access your count here

    RadListView1.AllowPaging = true;
    RadListView1.Rebind();

}


来源:https://stackoverflow.com/questions/19132355/how-to-get-radlistview-items-if-you-use-paging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!