我需要分页我的用户控件——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/