How to hide a DataPager control when there is only one page of data

When you are paging data in a ListView control using the DataPager, by default, the DataPager will be shown even if there is only one page of data. So, if you're using a NumericPagerField for example, you're going to end up with a text showing 1 in your page. So, in this cases, you might want to hide the DataPager control.
One way of achieving this is to change the visibility of the control on the DataBound event of the ListView control. For example:

 protected void ListView1_DataBound(object sender, EventArgs e)
{
  DataPager1.Visible = (DataPager1.PageSize < DataPager1.TotalRowCount);
}

In the example above, the DataPager is not inside the ListView control. If you place the DataPager inside the LayoutTemplate, then you have to tweak the code a little bit to find the control inside ListView. For example:

 protected void ListView1_DataBound(object sender, EventArgs e)
{
  DataPager pager = (DataPager) ListView1.FindControl("DataPager1");
  pager.Visible = (pager.PageSize < pager.TotalRowCount);
}

This way you can control whether you want the pager displayed or not.