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 %>" > <ItemTemplate> <uc1:MyControl ID="rowMyControl" runat="server" /> </ItemTemplate> <ItemStyle HorizontalAlign="Center" Width="30px" /> </asp:TemplateField>
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();
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();
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curpage - 1);
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.