I ran into a problem where the DataPager was not working how I expected when I followed the advice of most current blog posts. That is to re-databind to the ListView in the DataPager_PreRender. The problem was that it would not run any Eval statments in the item template or correctly run anything in the DataBound event of the ListView.
Here is the solution I found.
ASPX
<asp:ListView ID="ListView1" runat="server" >
<LayoutTemplate>
<div runat="server" id="itemPlaceholder"></div>
</LayoutTemplate>
<ItemTemplate>
<div runat="server">
<div>
<asp:Label runat="server" ID="Label1" Text='<%# Eval("myColumnName").ToString() %>' />
</div>
</div>
</ItemTemplate>
</asp:ListView>
<asp:DataPager runat="server" ID="DataPager1" PagedControlID="ListView1" PageSize="2" QueryStringField="paging" >
<Fields>
<asp:NumericPagerField ButtonCount="4" />
</Fields>
</asp:DataPager>
C#
protected void Page_Load(object sender, EventArgs e)
{
if(Request.QueryString["paging"] !=null)
{
int startRowIndex = 0;
//Get pageIndex from Query String
int paging = int.Parse(Request.QueryString["paging"].ToString());
//Subtract 1 to get to 0 based index
paging = paging - 1;
//Get the row to start the page
startRowIndex = DataPager1.PageSize * paging;
DataPager1.SetPageProperties(startRowIndex, DataPager1.PageSize, true);
}
DataTable dt1 = GetMyData();
ListView1.DataSource = dt1;
ListView1.DataBind();
}