LA.NET [EN]

Jan 03

Making the DataPager generate a block element

Posted in Uncategorized      Comments Off on Making the DataPager generate a block element

I do really like the new paging model introduced with the new ASP.NET 3.5 version. However, there is one thing I don”t like: the fact that the DataPager control will always generate an inline element (in this case, a SPAN). So, how can we change this default behavior? Well, I see at least 2 options:

  1. create a new derived control and override the TagKey property. From a conceptual view, I believe this is what should be done
  2. DataPager is a Control, so why not re-use our knowledge on how the parser performs its work and just drop a style attribute that sets its display mode to block (which will be automatically copied to the HTML tag that gets inserted in the page)

As I”ve said before, in real code I”d probably go with 1 since it feels more natural and I really don”t like adding style attributes to my HTML. On the other hand, it”s just too damn difficult to resist to something like this:

<asp:DataPager runat=”server” ID=”myPager”   
    style=”clear: both”         
    PageSize=”4″
    PagedControlID=”myList”>
    <Fields>           
        <asp:NumericPagerField ButtonCount=”5″                       
                ButtonType=”Link”
                RenderNonBreakingSpacesBetweenControls=”true” />                     
    </Fields>
</asp:DataPager>