|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionInstead of trying to create an enhanced Repeater, I decided to make a separate control that would take care of paging. This Having this functionality in a separate control allows you to add paging to any Web Control that accepts a data source. Also, you can place the
Navigation examples...
Postback or QueryString optionThis control also allows you to page through your collection with two different methods:
Using the ControlTo use the control, simply add a reference to the complied DLL and put it in your toolbox. You can then drag it to your project. If you wish to do it by hand, it'll look something like this in your .aspx file.... <%@ Register TagPrefix="cc1" Namespace="SiteUtils"
Assembly="CollectionPager" %>
<%@ Page language="c#" Codebehind="Example.aspx.cs"
AutoEventWireup="false" Inherits="CollectionPagerExample.WebForm1" %>
<HTML>
<HEAD><TITLE>Collection Repeater Example</TITLE></HEAD>
<BODY>
<DIV>
<ASP:LITERAL id=litDifferentResultsFormat runat="server"></ASP:LITERAL>
</DIV>
<DIV>
<ASP:LITERAL id=litTopPager runat="server"></ASP:LITERAL>
</DIV>
<ASP:REPEATER id="Repeater1" runat="server">
<HEADERTEMPLATE>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0">
<TR>
<TH>Header1</TH>
<TH>Header2</TH>
<TH>Header3</TH>
<TH>Header4</TH>
<TH>Header5</TH>
</TR>
</HEADERTEMPLATE>
<ITEMTEMPLATE><TR>
<TD><%# DataBinder.Eval(Container.DataItem, "Column1") %></TD>
<TD><%# DataBinder.Eval(Container.DataItem, "Column2") %></TD>
<TD><%# DataBinder.Eval(Container.DataItem, "Column3") %></TD>
<TD><%# DataBinder.Eval(Container.DataItem, "Column4") %></TD>
<TD><%# DataBinder.Eval(Container.DataItem, "Column5") %></TD>
</TR></ITEMTEMPLATE>
<FOOTERTEMPLATE>
</TABLE>
</FOOTERTEMPLATE>
</ASP:REPEATER>
<CC1:COLLECTIONPAGER id="CollectionPager1" runat="server">
</CC1:COLLECTIONPAGER>
</BODY>
</HTML>
In your code behind, you just feed the public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Repeater Repeater1;
protected SiteUtils.CollectionPager CollectionPager1;
private void Page_Load(object sender, System.EventArgs e)
{
//Create DataSet DataSet SampleDataSet = SampleData();
//Set DataSource of Pager to Sample Data
CollectionPager1.DataSource = SampleDataSet.Tables[0].DefaultView;
//Let the Pager know what Control it needs to DataBind during the PreRender.
CollectionPager1.BindToControl = Repeater1; //UPDATED!
//The Control now takes the object you are binding to,
// instead of the name of it (as a string)
//Set the DataSource of the Repeater to the PagedData coming from the Pager.
Repeater1.DataSource = CollectionPager1.DataSourcePaged;
//Done!
}
protected override void Render(HtmlTextWriter writer)
{
//Example of how to have the results show up in a different spot.
litDifferentResultsFormat.Text =
CollectionPager1.BuildResults("Currently viewing {0} through {1}");
//Example of how to have a second pager that is tied in...
litTopPager.Text = CollectionPager1.RenderedHtml;
base.Render (writer);
}
... other stuff ...
}
Control PropertiesThis control has a lot of properties that allow for customizing its appearance. Every section allows you to specify a
InstallationInstalling the controlYou can install the control in the standard way:
Installing the demoUnzip the ZIP file with the demo. Right-click on the "CollectionPagerExample" subfolder and select Properties. On the Properties window, click "web-sharing" and check "Share this folder". You should then be able to browse to: Opening the Solution in Visual StudioThere should be a "CollectionPagerSolution.sln" file in the root of the unzipped folder. When you open this file, you may be prompted for the CollectionPagerExample location. Use the Browse button to locate the CollectionPagerSample folder. Good Luck!!!Please let me know if you have any questions or thoughts. As this is my first CodeProject article, I hope that I was clear enough on what it does and how to use it. Thanks!!! Updates:2005/10/14
2005/05/26 (Major update)
2005/04/07
2005/03/22
2005/03/10
| ||||||||||||||||||||||||||||