Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old January 21st, 2004, 08:34 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I forgot to add allowcustompaging=true. however although now it doesn't throw an error it only gives me page 1 even though there should be more page numbers.

Reply With Quote
  #12 (permalink)  
Old January 21st, 2004, 08:37 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Yeah, I noticed that when I translated the code to VB.NET.

Basically, what happens is this:

1. First, we get a count of the number of controls minus 1. Let's say this this number is 11

2. Then we loop from 0 to 11 through the Controls of the pager and try to *copy* each control to the new pager bar.

3. However, the control is not copied, but it is moved to the new Pager bar. I guess this is caused by the fact that Controls are reference types. (You'll get a clean error description for this problem when you use a For Each myControl In MyPager.Controls instead of the indexer. The error message indicates that you are not allowed to change the collection while enumerating.)

4. Because the control is moved, the index of the Control array is decreased for each item. So, somewhere halfway down the road, your number of items is greater that the max index of the control.

I've been fiddling around a bit to see how to fix this. One way seems to *copy* the control to a control array, and then after the loop copy the controls in the array to the new Pager control. This seems like a bit of overhead to me, but at least it works. Here's a modification of the code:
Code:
Dim elemType As ListItemType = e.Item.ItemType
Select Case elemType
    Case ListItemType.Item, ListItemType.AlternatingItem
        ' If you need to deal with Item or AlternatingItem, do it here.
    Case ListItemType.Footer
        ' Same for the Footer
    Case ListItemType.Header
        ' And the Header
    Case ListItemType.Pager
        ' However, all we are interested in now is
        ' the Pager control
        Dim LoopCount As Integer

        ' Old Pager
        Dim pager As TableCell = CType(e.Item.Controls(0), TableCell)

        ' New Pager
        Dim newPager As TableCell = New TableCell

        ' See how many childs the Pager control contains
        Dim NumOfControls As Integer = pager.Controls.Count - 1

        ' Declare control for the Iterations
        Dim myControl As Control

        ' Create a new control array, top *copy* the original childs to
        Dim MyControls(NumOfControls) As Control
        For Each myControl In pager.Controls
            ' Copy the control to the array
            pager.Controls.CopyTo(MyControls, 0)
        Next

        ' Now loop through the array with child controls
        For Each myControl In MyControls
            ' And add each one to the new Pager bar
            newPager.Controls.AddAt(0, myControl)
        Next

        ' Remove the old Pager bar
        e.Item.Controls.RemoveAt(0)
        ' And add the new one
        e.Item.Controls.AddAt(0, newPager)
End Select
I think this is also the reason that my original implementation in C# lost the literal space controls between each LinkButton. I was in fact modifying the collection of controls, accidentally skipping each odd control.

Anyway, this seems to work, so have fun.


Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #13 (permalink)  
Old January 21st, 2004, 08:39 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

AllowCustomPaging should be set to False. This is used in scenario's where *you* control the amount of data retrieved from the datasource. When you use AllowCustomPaging="True", the DataGrid will show all items in the DataSource.

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #14 (permalink)  
Old January 21st, 2004, 10:11 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks soooooooo much and thanks for being so patient. :)
It works. If my boss asks can i take the credit for it??;)
Another question if you don't mind.
Is it possible to design the new pager? I want it to be dir=rtl as right now it is displayed as follows: 5,4,3,2,1,... and i want it to be ...,5,4,3,2,1.
Also, it is centered right (under the dg first row) and i want it centered in the middle.



Reply With Quote
  #15 (permalink)  
Old January 21st, 2004, 11:57 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Take credit for it?? Hmmm, well, whatever works for you. Although saying that you "had somebody else do it for you" would look even better on your management skills......

To center the footer, all you need to do is set horizontalalign="Center" in the FooterStyle.

I am not sure what you mean with the other question. On my test page, the pager looks like this:

... 5 4 3 2 1

when I set PageButtonCount to 5.

After all, the order of the entire Controls collection of the Footer is reversed.....

Imar



---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #16 (permalink)  
Old January 21st, 2004, 12:06 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Peter (planoie on this forum) suggested a nice solution. It's perfectly OK to *move* the controls from the old Pager bar to the new Pager. You just need to move them without getting into problems with the original collection, or with the control count.
This can easily be accomplished with the following code:
Code:
While (pager.Controls.Count > 0)
  ' Move pager.Control(0) to the new Pager bar.
End While
The final code for the reversed Pager bar should then look like this:
Code:
Dim elemType As ListItemType = e.Item.ItemType
        Select Case elemType
            Case ListItemType.Item, ListItemType.AlternatingItem
                ' If you need to deal with Item or AlternatingItem, do it here.
            Case ListItemType.Footer
                ' Same for the Footer
            Case ListItemType.Header
                ' And the Header
            Case ListItemType.Pager
                ' However, all we are interested in now is
                ' the Pager bar

                ' Get a reference to the old Pager bar
                Dim pager As TableCell = CType(e.Item.Controls(0), TableCell)

                ' Create the new Pager
                Dim newPager As TableCell = New TableCell

                ' Move the controls from the old Pager to the new Pager
                ' in reversed order.
                While (pager.Controls.Count > 0)
                    newPager.Controls.AddAt(0, pager.Controls(0))
                End While

                ' Remove the old Pager bar
                e.Item.Controls.RemoveAt(0)
                ' And add the new one
                e.Item.Controls.AddAt(0, newPager)
        End Select
        Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #17 (permalink)  
Old January 25th, 2004, 03:36 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar thanks soooo much for all your help. I didn't notice that i had dir=rtl in my td where i placed the dg and that is why the numbers appeared as 5,4,3,2,1...
Which method is better yours or Peter's and why?

Again, thanks so much for your help and your time- you have no idea how much you helped me out :)

Reply With Quote
  #18 (permalink)  
Old January 25th, 2004, 07:02 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You're welcome. Glad it worked out as planned.

Peter's method is better than the one I previously had. What Peter suggested was what I had in mind initially, but couldn't get it to work properly. My initial code moved the controls from the old pager to the new pager as well, but because of a bug in my loop counter, half the controls were skipped.

Moving the controls will be faster than creating a copy of them, so the last solution will perform better than the other solutions. It also saves you 4 lines of code ;)

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom paging in Datagrid with datagrid page count madhusrp ASP.NET 1.0 and 1.1 Professional 12 June 2nd, 2008 01:15 PM
Paging in DataGrid vijay_83 ASP.NET 2.0 Professional 0 September 29th, 2006 02:02 PM
datagrid-paging kvanchi ASP.NET 1.0 and 1.1 Basics 2 December 8th, 2004 04:17 AM
Paging in datagrid Renu ASP.NET 1.0 and 1.1 Basics 2 September 9th, 2004 01:11 PM



All times are GMT -4. The time now is 03:51 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.