2

我有一个带有自定义 PagerTemplate 的 FormView 控件和我自己的分页 LinkBut​​tons。在我加载的数据集只包含一个记录/项目并完全隐藏 PagerTemplate 之前,一切都很好。我在网上搜索了几个答案,只需添加:

protected void fvAppHMDA_PreRender(object sender, EventArgs e)
    {
        if (fvAppHMDA.TopPagerRow != null)
            fvAppHMDA.TopPagerRow.Visible = true;
    }

但是,这并没有什么不同。似乎当数据集中只有一条记录时,FormView.TopPagerRow 始终为空。似乎需要一种方法来拦截它,但我已经尝试在 OnPreRender 和 OnDataBound 事件中这样做,但仍然没有骰子。

如果有帮助,下面是我的代码示例:

ASPX

<asp:FormView ID="fvAppHMDA" runat="server" AllowPaging="True" DefaultMode="Edit" DataSourceID="dsLoanApplication" Width="100%" onpageindexchanging="fvAppHMDA_PageIndexChanging" OnDataBound="fvAppHMDA_DataBound" OnPageIndexChanged="fvAppHMDA_PageIndexChanged" OnItemCreated="fvAppHMDA_ItemCreated" DataKeyNames="ApplicationID" OnPreRender="fvAppHMDA_PreRender">
<PagerTemplate>
    <div class="tab_toolbar">
        <asp:LinkButton ID="lnkMoveFirst" runat="server" 
            ToolTip="Move to the First Application" CommandName="Page" 
            CommandArgument="First"><img src="images/icons/Icon_ArrowBackEnd.png" width="16" height="16" class="grid2" alt="Move to the First Application" /></asp:LinkButton>
        <asp:LinkButton ID="lnkMovePrevPage" runat="server" 
            ToolTip="Move to the Previous Page" CommandName="Page" 
            onclick="lnkMovePrevPage_Click" Enabled="False"><img src="images/icons/Icon_ArrowBackSkip.png" width="16" height="16" class="grid2" alt="Move to the Previous Page" /></asp:LinkButton>
        <asp:LinkButton ID="lnkMovePrevApp" runat="server" 
            ToolTip="Move to the Previous Application" CommandName="Page" 
            CommandArgument="Prev"><img src="images/icons/Icon_ArrowBack.png" width="16" height="16" class="grid2" alt="Move to the Previous Application" /></asp:LinkButton>
        <div class="grid2_container"><asp:TextBox ID="txtMoveNumber" runat="server" Text="0" Columns="5"></asp:TextBox> of <asp:Label ID="lblMoveTotal" runat="server" Text="0"></asp:Label></div>
        <asp:LinkButton ID="lnkMoveNextApp" runat="server" 
            ToolTip="Move to the Next Application" CommandName="Page" 
            CommandArgument="Next"><img src="images/icons/Icon_ArrowForward.png" width="16" height="16" class="grid2" alt="Move to the Next Application" /></asp:LinkButton>
        <asp:LinkButton ID="lnkMoveNextPage" runat="server" 
            ToolTip="Move to the Next Page" CommandName="Page" 
            onclick="lnkMoveNextPage_Click" Enabled="False"><img src="images/icons/Icon_ArrowForwardSkip.png" width="16" height="16" class="grid2" alt="Move to the Next Page" /></asp:LinkButton>
        <asp:LinkButton ID="lnkMoveLast" runat="server" 
            ToolTip="Move to the Last Application" CommandName="Page" 
            CommandArgument="Last"><img src="images/icons/Icon_ArrowForwardEnd.png" width="16" height="16" class="grid2" alt="Move to the Last Application" /></asp:LinkButton>
    </div>
</PagerTemplate>
<PagerSettings Mode="NextPreviousFirstLast" Position="Top" />
<EditItemTemplate>
    <!-- FORM CONTROLS HERE -->
</EditItemTemplate>

代码隐藏

protected void fvAppHMDA_PreRender(object sender, EventArgs e)
{
if (fvAppHMDA.TopPagerRow != null)
    fvAppHMDA.TopPagerRow.Visible = true;
}

protected void fvAppHMDA_DataBound(object sender, EventArgs e)
{
if (fvAppHMDA.DataItemCount != 0)
{
    // Update Current and Total Page
    ((Label)fvAppHMDA.TopPagerRow.FindControl("lblMoveTotal")).Text = fvAppHMDA.PageCount.ToString();
    ((TextBox)fvAppHMDA.TopPagerRow.FindControl("txtMoveNumber")).Text = (fvAppHMDA.PageIndex + 1).ToString();

    // Enable/Disable Page buttons based on Current Page
    if (fvAppHMDA.PageIndex + 1 == fvAppHMDA.PageCount)
    {
        ((LinkButton)fvAppHMDA.TopPagerRow.FindControl("lnkMoveLast")).Enabled = false;
        ((LinkButton)fvAppHMDA.TopPagerRow.FindControl("lnkMoveNextApp")).Enabled = false;
    }
    else if (fvAppHMDA.PageIndex == 0)
    {
        ((LinkButton)fvAppHMDA.TopPagerRow.FindControl("lnkMoveFirst")).Enabled = false;
        ((LinkButton)fvAppHMDA.TopPagerRow.FindControl("lnkMovePrevApp")).Enabled = false;
    }

    if (fvAppHMDA.PageIndex + 10 <= fvAppHMDA.PageCount - 1)
    {
        ((LinkButton)fvAppHMDA.TopPagerRow.FindControl("lnkMoveNextPage")).Enabled = true;
    }
    if (fvAppHMDA.PageIndex - 10 > -1)
    {
        ((LinkButton)fvAppHMDA.TopPagerRow.FindControl("lnkMovePrevPage")).Enabled = true;
    }

    fvAppHMDA.TopPagerRow.Cells[0].Visible = true;
}

if (fvAppHMDA.TopPagerRow != null)
    fvAppHMDA.TopPagerRow.Visible = true;
}

谢谢!

4

1 回答 1

2

试过这个http://forums.asp.net/t/1016811.aspx/1,它对我来说很好。如果你想要一个顶级寻呼机行,我猜 HeaderTemplate 也可以。

“在我设置的 FormView 的标记中:

AllowPaging="true"

PagerSettings-Visible="false"

然后我将所有用于分页的控件放在 FormView 的 FooterTemplate 中。通过这种方式,我仍然能够处理所有的分页事件,并且即使在数据源中只返回一条记录时,“Pager Row”也始终可见。”

于 2012-11-23T20:44:03.377 回答