Inserting Text before the Numberic Page numbers in paging

J

jmhmaine

How do Insert the word "Page:" in front of the auto-generated numbers in
paging?

For example, the bottom of the Datagrid currently just displays numbers:
1,2,3,4

I would like it to display:
Page: 1,2,3,4

Thanks.
 
K

Ken Cox [Microsoft MVP]

Hi,

Here's a sample that shows how to insert any text you want into the paging
area.

Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]


Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Private Sub DataGrid1_ItemCreated _
(ByVal sender As Object, ByVal e As _
DataGridItemEventArgs) Handles DataGrid1.ItemCreated
If e.Item.ItemType = ListItemType.Pager Then
Dim pager As TableCell
Dim lblMyText As New Label
lblMyText.Text = "Extra text goes here "
pager = CType(e.Item.Controls(0), TableCell)
pager.Controls.AddAt(0, lblMyText)
End If
End Sub

Function CreateDataSource() As ICollection
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("PercentValue", GetType(Double)))
dt.Columns.Add _
(New DataColumn("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 0.23 * (i + 1)
dr(3) = True
dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
Return dv
End Function 'CreateDataSource

<asp:DataGrid CssClass=gridstyle id="DataGrid1" runat="server"
ShowFooter="True" PageSize="2" AllowPaging="True">
<Columns>
<asp:BoundColumn DataField="Percentvalue" ReadOnly="True"
HeaderText="Percentvalue" DataFormatString="{0:p}"></asp:BoundColumn>
</Columns>
<PagerStyle Position="TopAndBottom" PageButtonCount="2"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
 
J

jmhmaine

That worked! It doesn't appear you need the <PagerStyle> tag if you set the
following in the datagrid tag:
AllowPaging="True"
PagerStyle-Mode="NumericPages"
PageSize="2"

Thanks.

Josh.

Ken Cox said:
Hi,

Here's a sample that shows how to insert any text you want into the paging
area.

Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]


Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Private Sub DataGrid1_ItemCreated _
(ByVal sender As Object, ByVal e As _
DataGridItemEventArgs) Handles DataGrid1.ItemCreated
If e.Item.ItemType = ListItemType.Pager Then
Dim pager As TableCell
Dim lblMyText As New Label
lblMyText.Text = "Extra text goes here "
pager = CType(e.Item.Controls(0), TableCell)
pager.Controls.AddAt(0, lblMyText)
End If
End Sub

Function CreateDataSource() As ICollection
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("PercentValue", GetType(Double)))
dt.Columns.Add _
(New DataColumn("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 0.23 * (i + 1)
dr(3) = True
dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
Return dv
End Function 'CreateDataSource

<asp:DataGrid CssClass=gridstyle id="DataGrid1" runat="server"
ShowFooter="True" PageSize="2" AllowPaging="True">
<Columns>
<asp:BoundColumn DataField="Percentvalue" ReadOnly="True"
HeaderText="Percentvalue" DataFormatString="{0:p}"></asp:BoundColumn>
</Columns>
<PagerStyle Position="TopAndBottom" PageButtonCount="2"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid>


jmhmaine said:
How do Insert the word "Page:" in front of the auto-generated numbers in
paging?

For example, the bottom of the Datagrid currently just displays numbers:
1,2,3,4

I would like it to display:
Page: 1,2,3,4

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top