Shredding, coding, arguing etc.

« Back to main article

Demonstration

Accessible version

Here is a demonstration of the accessible version of the paging control. Each link to a page is an html link and the page is determined using a value passed through the querystring.

The following list is created with a repeater, with my paging control coming afterwards.

  • Record 0
  • Record 1
  • Record 2
  • Record 3
  • Record 4
  • Record 5
  • Record 6
  • Record 7
  • Record 8
  • Record 9
Page 1 / 10

Less accessible version

Next we have the slightly-less accessible version (javascript must be enabled) that causes a postback using a LinkButton. This is useful for retaining form data when paging through records.

  • Record 0
  • Record 1
  • Record 2
  • Record 3
  • Record 4
  • Record 5
  • Record 6
  • Record 7
  • Record 8
  • Record 9
Page 1 / 10

ASPX Code

<asp:Repeater runat="server" ID="rptRecordsAccessible">
   <HeaderTemplate>
      <ul>
   </HeaderTemplate>
   
   <ItemTemplate>
      <li>Record <asp:Literal runat="server" ID="litDataItem" /></li>
   </ItemTemplate>
      
   <FooterTemplate>
      </ul>
   </FooterTemplate>
</asp:Repeater>
<paging:PagingAccessible runat="server" ID="accessiblePager" />

<asp:Repeater runat="server" ID="rptRecordsPostBack">
   <HeaderTemplate>
      <ul>
   </HeaderTemplate>
   
   <ItemTemplate>
      <li>Record <asp:Literal runat="server" ID="litDataItem" /></li>
   </ItemTemplate>
      
   <FooterTemplate>
      </ul>
   </FooterTemplate>
</asp:Repeater>

<paging:PagingPostBack runat="server" ID="postbackPager" CheckQuerystring="false" />

Code Behind

protected void Page_Load(object sender, EventArgs e)
{
   var data = new List<int>();

   for (int i = 0; i < 100; i++ )
   {
      data.Add(i);
   }

   rptRecordsAccessible.DataSource = accessiblePager.ExtractPage(data);
   rptRecordsAccessible.DataBind();

   rptRecordsPostBack.DataSource = postbackPager.ExtractPage(data);
   rptRecordsPostBack.DataBind();
}

Notice, in this case, that the data is broken up into pages using a method on the paging control. If you are dealing with hundreds of records then this method will perform badly. Instead you should do the paging at the database level and then set the FinalPage property of the paging control manually.

  •  
  • del.icio.us  del.icio.us
  • reddit  reddit
  • StumbleUpon  StumbleUpon