Home All Groups Group Topic Archive Search About

Inserting Text before the Numberic Page numbers in paging

Author
28 Feb 2005 4:45 PM
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.

Author
28 Feb 2005 9:26 PM
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>


Show quoteHide quote
"jmhmaine" <jmh@online.nospam> wrote in message
news:837FD612-DE11-4032-BEC3-2E89552B3947@microsoft.com...
> 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.
Author
28 Feb 2005 11:51 PM
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.

Show quoteHide quote
"Ken Cox [Microsoft MVP]" wrote:

> 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" <jmh@online.nospam> wrote in message
> news:837FD612-DE11-4032-BEC3-2E89552B3947@microsoft.com...
> > 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.
>
>
Author
28 Feb 2005 11:56 PM
Ken Cox [Microsoft MVP]
Hey Josh,

Thanks for reporting back.

Happy computing!

Ken

Show quoteHide quote
"jmhmaine" <jmh@online.nospam> wrote in message
news:B22C70E1-CF56-49C1-80DC-43298F958A2D@microsoft.com...
> 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.