ListView and DataPager

Now I’m really missing my CopyToHTML Plugin back from Visual Studio 2005 :o. Here is a little example on how to use the new ListView Control and DataPager of the .NET Framework 3.5:

<asp:ListView ID=”ListView1″ runat=”server” DataSourceID=”SqlDataSource1″ ItemContainerID=”DataSection”>

StartLayout:<br /><br />
<div id=”DataSection” runat=”server”></div>
EndLayout!<br /><br />

<div class=”usRevs”>
<div class=”criticscore”>
<%# DataBinder.Eval(Container.DataItem, “Rating”)%></div>
<div class=”criticreview”>
<div class=”quote”>
<%# DataBinder.Eval(Container.DataItem, “Title”)%></div>


<asp:DataPager ID=”DataPager1″ runat=”server” PagedControlID=”ListView1″ PageSize=”4″>
<fields><asp:nextpreviouspagerfield ButtonType=”Button” ShowFirstPageButton=”True” ShowNextPageButton=”False” ShowPreviousPageButton=”False” /><asp:numericpagerfield />
<asp:nextpreviouspagerfield ButtonType=”Button” ShowLastPageButton=”True” ShowNextPageButton=”False”
ShowPreviousPageButton=”False” />

<asp:SqlDataSource ID=”SqlDataSource1″ runat=”server” ConnectionString=”<%$ ConnectionStrings:LocalSqlServer %>”
SelectCommand=”SELECT [Title],[Rating],[Description],[Developer] FROM [gf_game]”></asp:SqlDataSource>

That’s it, here is how it looks:
ListView Datapager

However, there is one big downside of the DataPager: If you build a Website which needs to score in SEO matters you wouldn’t want to use the DataPager. As of now the links to the pages look like that:


A SearchEngine won’t be able to follow this link, which means you eventually run into problems if you want to get a heavy paged site indexed in a SearchEngine by using the DataPager Module in that kind of way.

Here’s how it would need to look like for e.g. page 2: or even better:

The PagerData Control is really amazing but if it’s missing the SEO aspect I can’t use it for my public SEO oriented sites..

UPDATE: Here you can find a querystring based DataPager built by Polita Huff: click. Great!


#1 Rick Strahl on 08.02.07 at 5:27 am

Andreas, thanks for posting this. I just started taking a look at the ListView and DataPager as well.

The DataPager seems a very odd piece of code. Doesn’t work without ViewState and it doesn’t have any properties or events to explicit set pages which seems a very odd choice for a component that has such a singled minded function…

#2 andreas.kraus on 08.02.07 at 9:13 am

Hello Rick,

I agree with you, at the moment the DataPager is really missing important properties.

However, Scott mentioned that he’s bugging the Web-Team to give the DataPager more love for the final release, so let’s see how it looks like in the end.. Would be a pitty if it stays like that actually.

#3 DataPager in .Net 3.5 at Varun on the Web on 08.09.07 at 5:23 pm

[…] Head over here for a nice example├é […]

#4 Krish on 07.02.08 at 12:03 pm

Really nice one !!!
is it possible to remove … (means, navigate to the next or previous set of pages) from data pager control?

#5 Varun on 10.22.08 at 6:21 pm

Great Article,

#6 Varun on 10.22.08 at 6:22 pm

Just one thing I want to know as If I want to set the Page size at runtime how can I do that.

#7 Vino on 10.25.08 at 8:02 pm

Is it possible to share a datapager with two or more listviews which have the same datasource? I’m thinking of having diffrent style for my resultset that i can switch.

Leave a Comment