Reputation: 852
I am trying to add a button control to right of the previous/next of pager in asp.net gridview. I've tried to work with examples on this site, but I need to keep the previous/next and put the button to the right of the bottom pager row.
At first I got a small (5px) it to show in the next cell, then after numerous other attempts, in now doesn't even appear.
How do I align a button to the right while keeping gridview generated next/previous buttons.
Thanks
Private Sub grdClientServiceType_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdClientServiceType.RowCreated
Select Case e.Row.RowType
Case DataControlRowType.Pager
'Dim space As New LiteralControl(" ")
'Dim span1 As New Label
'span1.Text = " "
'span1.Style("margin-left") = "50px"
'Dim butt As New Button
'butt.ID = "buttShowAvail"
'butt.BackColor = Drawing.Color.Purple
'butt.ForeColor = Drawing.Color.White
'butt.Font.Bold = True
'butt.ToolTip = "Click for a selection of times available."
'Dim table As Table = TryCast(e.Row.Cells(0).Controls(0), Table)
'Dim parentCell As TableCell = table.Rows(0).Cells(table.Rows(0).Cells.Count - 1)
'Dim w As Integer = parentCell.Width.Value
'parentCell.Controls.Add(space)
'parentCell.Controls.Add(butt)
Dim butt As New Button
butt.ID = "buttShowAvail"
butt.BackColor = Drawing.Color.Purple
butt.ForeColor = Drawing.Color.White
butt.Font.Bold = True
butt.ToolTip = "Click for a selection of times available."
AddHandler butt.Click, AddressOf buttShowAvail_Click
e.Row.Cells(0).ColumnSpan -= 1
Dim td As New TableCell
Dim span1 As New Label
span1.Text = "Show"
span1.Style("margin-left") = "10px"
td.Controls.Add(span1)
td.Controls.Add(butt)
Dim span2 As New Label
span2.Text = "rows per page"
td.Controls.Add(span2)
e.Row.Cells.Add(td)
End Select
End Sub
Upvotes: 2
Views: 1679
Reputation: 852
I finally figured it out, thanks to this site. I just need to change a few things to get this to work.
The solution is below...
Private Sub grdClientServiceType_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdClientServiceType.RowCreated
Select Case e.Row.RowType
Case DataControlRowType.Pager
Dim butt As New Button
butt.ID = "buttShowAvail"
butt.BackColor = Drawing.Color.Purple
butt.ForeColor = Drawing.Color.White
butt.Font.Bold = True
butt.ToolTip = "Click for a selection of times available."
butt.Width = "220"
butt.Height = "40"
butt.Text = "Show Availability"
butt.Font.Size = "11"
AddHandler butt.Click, AddressOf buttShowAvail_Click
e.Row.Cells(0).ColumnSpan -= 1
Dim td As New TableCell
td.Controls.Add(butt)
e.Row.Cells.Add(td)
End Select
End Sub
Upvotes: 4