|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Inserting Text before the Numberic Page numbers in pagingHow 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. 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. 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. > > 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.
Default Paging
Dynamically created control in Datagrid problem Changing paging look TemplateColumn with CheckBox DataBind in C# recursive relation in datagrid Paging Problem GUI of Datagrid To stop text wraping in an datagrid asp.net 2003 MSDN UNIVERSAL NG SUPPORT: Where Are You?! <--- 3rd Re-Post Datagrid Edit DropdownList Help! |
|||||||||||||||||||||||