c# - 如何向用户控件添加分页?

标签 c# .net user-controls paging

我需要分页我的用户控件——8 或 10 组应该看起来不错。目前,它们位于占位符中:

<asp:PlaceHolder ID="ProfileContainer" runat="server"></asp:PlaceHolder>

占位符是这样填充的:

var model = //LINQ to Entities query

foreach(var profile in model) {
    Controls_Profile profile = (Controls_Profile)Page.LoadControl("~/Controls/Profile.ascx");

    profile.Name = model.Name;
    //more properties
    ProfileContainer.Controls.Add(profile);
}

如果我有数百个配置文件,我如何对结果进行分页?我发现的大多数帖子都与创建仅对表格分页的自定义分页控件有关。

我考虑过创建一个计数器,在第一个控件前加上 <div id="Group1"> .在 8 或 10 个控件之后,附加 </div> .我可以使用 jQuery 插入上一个/下一个链接并根据组号控制它们的流量。但是,我该怎么做Response.Write("<div id="groupx">");在添加控件时在循环中间?那怎么行呢?

最佳答案

关于我的评论:

public DataTable getControls()
{
     DataTable dt = new DataTable();
     //Code to populate table
    return dt;
}

和:

<asp:GridView ID="YourGridView" AllowPaging="true" DataSource='<%# getControls() %>'></asp:GridView>

我担心您的数据源必须具有某种可枚举的接口(interface)才能使分页正常工作。

如果失败,我建议您阅读常见的分页技术并手动实现一些操作。没有您想的那么难。

关于c# - 如何向用户控件添加分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4226483/

相关文章:

c# - 使用 html Agility Pack 选择属性值

c# - 将 System.Json 用于非 Silverlight 项目?

wpf - 共同的共享 View 。 View + View 模型或用户控件?

c# - 动态加载用户控件

c# - 在运行时更改表达式委托(delegate)主体?

c# - CSS - 在 Outlook 浏览器中设置图像大小

c# - Hangfire 即使在不活动时也会继续运行 SQL 查询

c# - 我怎样才能快速计算字符串出现在字符串列表的给定部分中的频率?

asp.net - DropDownList OnSelectedIndexChange to 0th index w/out ViewState

C#如何防止数据库中出现重复数据?