定制pagertemplate [英] custom pagertemplate

查看:144
本文介绍了定制pagertemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认寻呼机机构插入的最后一行中的表,则此表中包含一个行与根据需要包含页编号(Ⅰ设置页面模式到数字),为许多细胞。相反,有这种嵌套表,我想创建一个包含被浮动到对方左侧小广场的div一个pagertemplate,每个箱子里面的页码。

The default pager mechanism inserts a table in the last row and then this table contains one row with as many cells as needed that contain page number (I set the page mode to numeric). Instead of having this nested table, I'd like to create a pagertemplate that consists of small square divs that are floated to the left of each other, with the page number inside each box.

如何创建这样一个寻呼机模板?

How do you create a pager template like that?

感谢

推荐答案

将PagerTemplate内Repeater控件如下:

Place a Repeater control inside the PagerTemplate as follows:

   <PagerTemplate>
        <asp:Repeater ID="repFooter" OnItemCommand="repFooter_ItemCommand" runat="server">
            <HeaderTemplate>
                <div class="pager">
            </HeaderTemplate>
            <ItemTemplate>
                <div class="page">
                    <asp:LinkButton ID="lnkPage" Text='<%# Container.DataItem %>' CommandName="ChangePage" CommandArgument="<%# Container.DataItem %>" runat="server" />
                </div>
            </ItemTemplate>
            <FooterTemplate>
                    <div class="clear"></div>
                </div>
            </FooterTemplate>
        </asp:Repeater>
    </PagerTemplate>

然后添加一个事件处理程序网格的数据绑定事件,设定DataSource的转发如下:

Then add an event handler for the Grid's DataBound event which sets the datasource for the repeater as follows:

protected void GridView1_DataBound(object sender, EventArgs e)
{

    GridViewRow pagerRow = GridView1.BottomPagerRow;

    if (pagerRow != null)
    {

        Repeater repFooter = (Repeater)pagerRow.Cells[0].FindControl("repFooter");

        List<int> pages = new List<int>();

        for (int i = 0; i < GridView1.PageCount; i++)
        {
            pages.Add(i + 1);
        }

        repFooter.DataSource = pages;
        repFooter.DataBind();
    }
}

添加事件处理程序来处理中继的ItemCommand事件如下:

Add an event handler to handle the ItemCommand event of the repeater as follows:

protected void repFooter_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    if (e.CommandName == "ChangePage")
    {
        GridView1.PageIndex = Convert.ToInt32(e.CommandArgument) - 1;
    }
}

下面是替换为一个下拉列表中的默认寻呼机MSDN上的另一样本:
<一href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.pagertemplate.aspx\">http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.pagertemplate.aspx

Here is another sample on MSDN which replaces the default pager with a drop-down list: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.pagertemplate.aspx

这篇关于定制pagertemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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