C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

Change the datagrid footer text


Posted Date: 04 Jun 2004    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: ManojRajanMember Level: Gold    
Rating: 1 out of 5Points: 7



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




Responses

Author: critic    07 Jun 2004Member 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 2004Member Level: Gold   Points : 0
As per your request, the article now has the explanation.

ManojRajan


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Two ways sorting in a datagrid
Previous Resource: ViewState and Performance
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use