开发者

How can I add paging to user controls?

I need to page my user controls--groups of 8 or 10 should look nice. Currently, they're in a place开发者_JS百科holder:

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

And the placeholder is populated like this:

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);
}

How can I page the results in the event I have hundreds of profiles? Most posts I find are related to creating a custom paging control that just pages a table.

I thought about creating a counter that would prepend the first control with <div id="Group1">. After 8 or 10 controls, append </div>. I could use jQuery to insert previous/next links and control their flow based on the group number. But, how do I do Response.Write("<div id="groupx">"); in the middle of the loop as the controls are being added? How would that even work?


Regarding my comment:

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

And:

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

I fear that your datasource has to have an enumerable interface of some kind in order for paging to work though.

If this fails, I suggest you read up on common paging techniques and implement something manual. Not as hard as you think.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜