Der deutsche Education Blog

March, 2008

  • Maíra Wenzel's Blog

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

    • 6 Comments

    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.

  • Maíra Wenzel's Blog

    Inaugural Post

    • 0 Comments

    It's been a while that I've been thinking about starting my own blog, and I finally decided to do it!

    I just came back from Mix08, where I had the chance to talk to a lot of our customers and I heard that the majority of them use blogs to learn more about ASP.NET. So I'll use my blog to talk about ASP.NET and whatever else is on my mind.

    And for those that couldn't go to Mix08, the sessions are available online at http://sessions.visitmix.com/.

    Enjoy!

Page 1 of 1 (2 items)

March, 2008