【问题标题】:Adding Link Button to footer of GridView in ASP.NET在 ASP.NET 中将链接按钮添加到 GridView 的页脚
【发布时间】:2011-04-24 05:14:14
【问题描述】:

我该怎么做?基本上,在 GridView 中的页码旁边,我想要一个链接按钮来禁用分页。这可行,但我想要 GridView 的页脚内的按钮,靠近页码。我该怎么做?

【问题讨论】:

    标签: asp.net gridview footer


    【解决方案1】:

    您可以在代码隐藏中添加以下内容(假设 VB.Net 可以):

     Private Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
        Select Case e.Row.RowType
            Case DataControlRowType.Footer
                Dim LnkBtnPaging As New LinkButton
                LnkBtnPaging.ID = "LnkBtnPaging"
                LnkBtnPaging.Text = IIf(GridView1.AllowPaging, "no paging", "paging").ToString
                AddHandler LnkBtnPaging.Click, AddressOf LnkBtnPagingClicked
                e.Row.Cells(0).Controls.Add(LnkBtnPaging)
                e.Row.Cells(0).ColumnSpan = e.Row.Cells.Count
                While e.Row.Cells.Count > 1
                    e.Row.Cells.RemoveAt(e.Row.Cells.Count - 1)
                End While
        End Select
    End Sub
    
    Private Sub LnkBtnPagingClicked(ByVal sender As Object, ByVal e As EventArgs)
        Me.GridView1.AllowPaging = Not Me.GridView1.AllowPaging
    End Sub
    

    记得将网格的 ID 更改为您的 ID,并在 ASPX 的 GridView 的标签中添加 ShowFooter="True"

    编辑:添加代码以自动调整页脚的列数和列跨度

    【讨论】:

      【解决方案2】:

      您可以创建 GridView 的 PagerTemplate。在这种情况下,您可能必须从头开始创建整个寻呼机。

      您还可以创建自己的从 GridView 派生的控件并覆盖 InitializePager。在此方法中,您将调用 base.InitializePager(...),然后您将在创建的控制结构中导航并添加您的链接。

      编辑: Tim 的解决方案更好。我的解决方案有效,但是当您禁用分页时,链接将与分页器一起隐藏。

      【讨论】:

        猜你喜欢
        • 2017-07-15
        • 1970-01-01
        • 2010-12-23
        • 1970-01-01
        • 2013-01-08
        • 1970-01-01
        • 1970-01-01
        • 2012-09-11
        • 1970-01-01
        相关资源
        最近更新 更多