Put this code in the ItemCreated event of the datagrid. The ItemCreated event is triggered on each row item of the datagrid. DGList is the name of the datagrid.
'This line will check the type of the row item in the datagrid, which is created 'This code is for checking whether the currently created row item is a header control
If e.Item.ItemType = ListItemType.Header Then 'In the header control, create a Label control and set the text property to the desired value 'and add this control to the header
Dim lb As New Label() lb.Text = "Page " & (DGList.CurrentPageIndex + 1) & " of " & DGList.PageCount lb.Font.Bold = True
'Add the newly added control to the rows first cell e.Item.Cells(0).Controls.AddAt(0, lb) End If
'This code is for checking whether the currently created row item is a Pager control
If e.Item.ItemType = ListItemType.Pager Then 'Add one label control and set the text property to the value which will come before the 'Page numbers Dim lb As New Label() lb.Text = "Page No. : " lb.Font.Bold = True 'Add it to the row e.Item.Cells(0).Controls.AddAt(0, lb)
'This code will create the Page numers with the desired format
Dim pageIndex As Integer
'This variable is required for referencing the first cell of the row
Dim pager As New TableCell()
'Assign the reference to the variable pager = e.Item.Controls(0)
'now the pager has the reference of the pager control 'Pager control shows each page number as a link control except 'for the current page, which will be a label control. So at a time a pager will 'have only one label control pointing to the current page number 'We need to trace it, for formating 'Iterate through the pager's control collection
For pageIndex = 1 To pager.Controls.Count - 1 'Assign the refrence to a generic object
Dim o As Object = pager.Controls(pageIndex)
'Check the type of the control, if it is a label control, 'this is the one we have to format.
If TypeOf o Is Label Then
'Assign this object to a newly created label control.
Dim l As Label = o l.Text = l.Text l.Font.Bold = True l.ForeColor = l.ForeColor.DarkOrange l.Height = l.Height.Pixel(12) End If Next End If
|
| Author: critic 07 Jun 2004 | Member Level: Bronze Points : 0 |
Nice and short article. If you can add some explanation about the logic used, that would add more value to it.
|
| Author: ManojRajan 08 Jun 2004 | Member Level: Gold Points : 0 |
As per your request, the article now has the explanation.
ManojRajan
|