[RESOLVED] paging

I have a webpage where I am adding UserControls on the fly depending upon number of rows in a dataset. row data feeds the usercontrol.

I want to add paging if number of usercontrols is more that 5, which in turn means if number of rows in the dataset is more than 5. It is like this forum where it pages based upon number of replies to a post.  

Any best practices?

yeah, this could be one option. I am looking for a more elegant solution. I don't want to use dropdowns for page navigation.


If I am not wrong then you have created one use controls for displying set of item just like one row and you are adding that contrils to show list of data (as no of rows) and now you want to establish paging for this functionality.


Then you can use datagird, gridview or repeater cotrol and add you user contorl in itemtemplate of dataview. 

<asp:TemplateField HeaderText="<%$ Resources:KHResource, Actions %>" >
        <uc1:MyControl ID="rowMyControl" runat="server" />
     <ItemStyle HorizontalAlign="Center" Width="30px" />

for Paging you can set avalalbel paging for your grid view controls. no need to extra things to implement


Mark as answered if this is helps 


I need to set some properties of User Control from row data. Please suggest if this is possible with this approach. 

Hi, You can try like this .... I have used this for repeater ..you can use this for some other control alsp ...have a look ...

SqlDataAdapter da = new SqlDataAdapter(sqlstring, connection);
        DataSet ds = new DataSet();
        da.Fill(ds, "image_data");
        PagedDataSource pageds = new PagedDataSource();
        pageds.DataSource = ds.Tables["image_data"].DefaultView;
        pageds.AllowPaging = true;
        pageds.PageSize = 5;
        int curpage = 0;

        if ((Request.QueryString["Page"] != null))
            curpage = Convert.ToInt32(Request.QueryString["Page"]);
            curpage = 1;

        pageds.CurrentPageIndex = curpage - 1;
        lblCurrpage.Text = "Page: " + curpage.ToString();

        if (!pageds.IsFirstPage)
            lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curpage - 1);

        if (!pageds.IsLastPage)
            lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curpage + 1);

        Repeater1.DataSource = pageds;


Hi vaibhav, I am able to set the properties too in the template field method. Thanks for the inputs.  

thoughts on "[RESOLVED] paging"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>