自ASP.Net DataPager的生成的HTML [英] Customize ASP.Net DataPager generated HTML

查看:190
本文介绍了自ASP.Net DataPager的生成的HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是ListView和DataPager的在分页我的web项目。它工作正常,但对于分页生成的HTML只是一个包含一些链接的跨度。

I am using a ListView and DataPager in my web project for pagination. It works fine, but the generated HTML for the pagination is simply a span containing some hyperlinks.

我想自定义HTML并显示在一个无序列表,而不是(UL)。

I wanted to customize the HTML and display the links in an unordered list instead (ul).

有人知道如何可以做到这一点?我能想到的一个方法是CSSFriendly适配器,但我不想这样做,如果有一个更简单的方法。

Anybody know how this can be done? One way I can think of is CSSFriendly adapters, but I don't want to do that if there is an easier way.

编辑:可能有人帮助我创建模板控件所需的具体步骤?遗憾的是愚蠢的,但我不能这部分弄清楚,尽管广泛的谷歌搜索。

Could somebody help me out with the exact steps required to create the controls in the template? Sorry for being daft, but I can't figure this part out, in spite of extensive Googling.

推荐答案

您可以使用PagerTemplate指定要使用分页控件的标记。我不知道你想在显示寻呼信息一样UL /李方面做的事情,但是这应该是足够的,开始你在正确的轨道上。对不起,长期运行到一边......

You can use the PagerTemplate to designate the markup you'd like to use for the paging control. I'm not sure exactly what you're trying to do in terms of displaying the paging information as as ul/li, but this should be enough to start you on the right track. Sorry for the code running long to the side...

例如:

<asp:DataPager ID="DataPager1" runat="server" PagedControlID="gridInvoiceHistory"
            PageSize="20">
            <Fields>
                <asp:TemplatePagerField>
                    <PagerTemplate>
                        Page
                        <asp:Label runat="server" ID="labelCurrentPage" Text="<%# Container.TotalRowCount > 0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>" />
                        of
                        <asp:Label runat="server" ID="labelTotalPages" Text="<%#  Math.Ceiling ((double)Container.TotalRowCount / Container.PageSize) %>" />
                    </PagerTemplate>
                </asp:TemplatePagerField>

编辑:这里有一个更详细的开始了一个解决方案:

here is a more detailed beginning to a solution for this:

<asp:TemplatePagerField>
     <PagerTemplate>
          <asp:BulletedList ID="listPages" runat="server" 
               DisplayMode="LinkButton" onclick="listPages_Click">
          </asp:BulletedList> 
     </PagerTemplate>
</asp:TemplatePagerField>

这是你会在code-背后究竟:

And here is what you would have in the code-behind:

protected void listPages_Click(object sender, BulletedListEventArgs e)
        {
            var pageNo = int.Parse((sender as BulletedList).Items[e.Index].Text);
            var startIndex = (pageNo - 1) * DataPager1.PageSize;
            DataPager1.SetPageProperties(startIndex, DataPager1.PageSize, true);
        }

剩下的给你做的是对的获取页面的计数,并返回所需的文本的页面链接的IEnumerable列表的方法的项目符号列表上执行数据绑定。标准的警告:这是样品code和可能不应该在生产环境中没有一个彻底的审查使用! :)

What remains for you to do is to perform a databinding on the bulleted list against a method that gets the page count and returns an IEnumerable list of the text you want for the page links. Standard warning: this is sample code, and probably shouldn't be used in a production environment without a thorough vetting! :)

这篇关于自ASP.Net DataPager的生成的HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆