home

my blog

check me out!

GRIDVIEW - Add View All button to GridView Pager Row

        Protected Sub MyGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
            If e.Row.RowType = DataControlRowType.Pager Then
                Dim space As New LiteralControl(" ")

                Dim lb As New LinkButton()
                lb.ID = "ViewAllLinkButton"
                lb.Text = "View All"
                lb.SkinID = "ProfessionalGridViewPagerViewAll"
                AddHandler lb.Click, AddressOf ViewAllLinkButton_Click

                ' Pager is rendered in a single cell as a table; 
                ' each page # is in a cell by it's own
                Dim table As Table = TryCast(e.Row.Cells(0).Controls(0), Table)

                ' Add ViewAll linkbutton to the last cell
                Dim parentCell As TableCell = table.Rows(0).Cells(table.Rows(0).Cells.Count - 1)
                parentCell.Controls.Add(space)
                parentCell.Controls.Add(lb)
            End If
        End Sub

        Protected Sub ViewAllLinkButton_Click(ByVal sender As Object, ByVal e As EventArgs)
            GridView1.AllowPaging = False
        End Sub