Paging Repeater treating page 11 as "1" and "1" not "11"

Dear All

I have a paging repeater, and I am displaying pages according to the amount of records I am retreiving from the database.  

My code is as follows:-

ASPX

           <asp:Repeater runat="server" ID="rptPageNumbers" OnItemCommand="rptPageNumbers_ItemCommand">
              <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Container.DataItem %>'
                 CommandArgument='<%# Container.DataItem %>' />&nbsp;&nbsp;
              </ItemTemplate>
           </asp:Repeater>

ASCX

        public void PopulatePages()
        {
            string strPageNumbers = "";
            if ((TotalRecords > 0) && (TotalRecords > PageSize))
            {
                //divide the TotalRecords By the Pagesize to get the Total of whole numbers
                double dWholeNumbers = (TotalRecords / PageSize);
                double dRemainder = (TotalRecords % PageSize);

                for (int i = 0; i < Convert.ToInt32(dWholeNumbers); i++)
                {
                    strPageNumbers += (i + 1) + ";";
                }

                //if there is a remainder, than add another integer to the string
                if (dRemainder > 0)
                    strPageNumbers += (dWholeNumbers + 1) + ";";

                strPageNumbers = strPageNumbers.Replace(';', '|');
                rptPageNumbers.DataSource = strPageNumbers;
                rptPageNumbers.DataBind();

                pnlPageNumbers.Visible = true;

            }
            else
            {
                strPageNumbers = "";
                pnlPageNumbers.Visible = false;
            }
        }

Everything is working well, however, when i get more than 10 pages, for example "11", "12", "13", its treating them as single numbers, for example "1" and "2" for "12".

 

Does anyone has any suggestion on how I might concatenate them together to show a single page?

Thanks for your help and time

 

0
monfu
3/23/2009 10:38:02 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
1092 Views

Similar Articles

[PageSpeed] 38

Hi,

Here you are assigning a string as the "DataSource" for the "Repeater" control. So all the values present in that string will be considered as single items. So if the string contains "1|2|3|10" then each elements 1, |, 2, |, 3, |, 1,0 wil be considered as individual items and link will be created for each of these items.

You can avoid this by using an Array or ArrayList in place of string.

I have modified your code to use an ArrayList. (Modified part in Bold Red)

<asp:Repeater runat="server" ID="rptPageNumbers" 
                                                          OnItemCommand="rptPageNumbers_ItemCommand">
              <ItemTemplate>
                  <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Container.DataItem %>'
                   CommandArgument='<%# Container.DataItem %>' />&nbsp;&nbsp;|
              </ItemTemplate>
 </asp:Repeater>
 
(Added the page number divider "|" in aspx page as I am going to pass it to the Repeater)

 

public void PopulatePages()
        {
            string strPageNumbers = "";
            ArrayList arrPageNumbers = new ArrayList();
            if ((TotalRecords > 0) && (TotalRecords > PageSize))
            {
                //divide the TotalRecords By the Pagesize to get the Total of whole numbers
                double dWholeNumbers = (TotalRecords / PageSize);
                double dRemainder = (TotalRecords % PageSize);

                for (int i = 0; i < Convert.ToInt32(dWholeNumbers); i++)
                {
                    //strPageNumbers += (i + 1) + ";";
                    arrPageNumbers.Add(i + 1);

                }

                //if there is a remainder, than add another integer to the string
                if (dRemainder > 0)
                    //strPageNumbers += (dWholeNumbers + 1) + ";";              
                    arrPageNumbers.Add(arrPageNumbers.Count + 1);

               
//strPageNumbers = strPageNumbers.Replace(';', '|');
                //rptPageNumbers.DataSource = strPageNumbers;
                rptPageNumbers.DataSource = arrPageNumbers;

                rptPageNumbers.DataBind();

                pnlPageNumbers.Visible = true;

            }
            else
            {
                strPageNumbers = "";
                pnlPageNumbers.Visible = false;
            }

-- Anoop

 


"I would love to change the world, but they won’t give me the source code"
0
anoopmms
3/24/2009 9:14:03 AM

 excellent

 thanks for the information!

It works brilliantly
 

0
monfu
3/24/2009 9:44:49 AM

Happy to know that it helped you...

 --Anoop

 Please mark as Answer if the reply solves your problem.


"I would love to change the world, but they won’t give me the source code"
0
anoopmms
3/27/2009 8:31:04 AM
Reply:

Similar Artilces:

Precedence of "where" ("of", "is", "will")?
Nobody on #perl6 today could answer this one. Is: Str | Int where { $_ } the same as: (Str | Int) where { $_ } or: Str | (Int where { $_ }) ? Followup questions, Mr. President: What kind of operators are "where", "of", "is", and "will"? Is there a reason that S03 doesn't list them? What are their precedence(s)? -- Chip Salzenberg - a.k.a. - <chip@pobox.com> Open Source is not an excuse to write fun code then leave the actual work to others. Chip Salzenberg writes: &...

.ALLCOL("%COLUMN%", " ", ", ", ", ")
Do you know anyway for me to exclude a subset of columns returned by this function. We have two columns (rec_user and rec_datetime) which are in all of our tables, but when generating triggers I want automatically generate a script which does not include those two columns but does include all other columns in that table. Bruce I should add that I am using PD 9.0.0.580. Bruce "Bruce Lamb" <lamb.bruce@mayo.edu> wrote in message news:6HgI315nCHA.155@forums.sybase.com... > Do you know anyway for me to exclude a subset of columns returned by this > function. ...

Swap a "1" or "0" for a "Y" or "N"
I have a sql query that returns rows of data and one field returns a 1 (which means yes) or a 0 (which means no).  On my vb.net page, how do I replace the 1 with a Yes and the 0 with a No?  Or do I do this in the sql?  How do I do this in sql?Never make important decisions on a Monday! By default, VB.Net can understand 1 as Yes and 0 as No.I believe you are using those DB values for your Boolean Operations.Try to use If <DBValue> then <Operation>. If you are really need Yes/No .... Declare boolean variable in VB.net and set those variables. Thanks and R...

quotes, quotes, quotes...
I am getting this error and I know what is causing it, but I have no idea how to fix it, any help would be great. The script steps through the /var/log/messages file on a linux server and puts The entries into a mysql database. However when it gets to the 'hlt' line in the messages file it just barfs. The single quotes are freaking it out. I know about quotes but not how to use in this situation. Thanks, Paul Error: May 27 17:53:00 localhost kernel: Checking 'hlt' instruction... OK. <----- doesn't like this in the messages file DBD::mysql::st exec...

Mac OsX -no "page down" or "page up"
Name: Kurt Email: bruderkurt_at_yahoo.com Product: Bon Echo Summary: Mac OsX -no "page down" or "page up" Comments: Congratulations to you on Bon Echo Alpha 1! I'm using OSx for the Mac and the "page down" and "page up" buttons don't operate with Bon Echo (when wanting to scroll the page itself). They haven't operated with earlier Mac Firefox versions either, in my experience. I love Firefox, its speed and features. I'm loving the same and more with Bon Echo Alpha 1. The "page down" and "page up" wor...

"Error on page" when clciking "Jobs" in "Printer Control" with iManager
Hello all, I have the following issue in iManager : when I click on "Jobs" in "Printer Control" tab for a printer object, I have the following error message : "Error on page"/"Done with Error" in the left down corner of my Internet Explorer (v6.0) If I double click on the error message, I have either "Expected ')'" or "Object Expected" in the error description window. What surprise me is the fact that it occurs only on printers from one of our four NDPSM. (This is why I didn't post on the imanager forum) Tho...

"Page Inherits" , "Namespace" , "Register TagPrefix" , & "Assembly"
Hi,         I'm just start learning web matrix, can anyone explain to me about the "Page Inherits" , "Namespace" , "Register TagPrefix" , & "Assembly"  Thanks you~~          Most of the information you are asking you can get definitions from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconPage.asp linkHope it helps!Sreedharhttp://www.w3coder.orgweblog http://weblogs.asp.net/skoganti Thanks a lot! :)...

what's the different from "<page src="">" and "<page codeBehind="">"
what's the different from "<page src="">" and "<page codeBehind="">" Thank YOU how to make session' life longer? Thank You This very question was asked only 5 days ago. Searching the forums would have yielded the answer you require. However, see this thread. Steven BeyRecursion: see Recursion You can set a new value for the Session Timeout in your web.config file. Or, you can do it in a page through this property: Session.Timeout Note that if you choose the second method, the timeout will only be modified on this page,...

"Using" or "With"
Hi all Please can someone enlighten to me as regards the difference with the "Using" and "With" statement when accessing data - which is better, what are the limitations and/or any pointers. Many thanks. Regards DaveDavid WinchesterPlease mark as answer if this is the solution.  using gives you the ability to use the connection and it closes the connection directlly after you finish using it. and there is no need to try- cach - finaly. there is no limitation on using USING keywordMuhanad YOUNISMCSD.NETMy Blog || My Photos || LinkedIn I have a dataobject the re...

"To" and "From" missing
When I print emails, the words "To" and "From" are blank, even though the "To" name and "From name (addresser, addressee) do show up. This is not a problem for other users on my system. Suggestions In mailbox right click, view. On the message window, right click and choose print options. Make sure print header is checked. -- Barry Merchant NSC Volunteer SysOp *** no email unless requested please!! *** > In mailbox right click, view. On the message window, right click and > choose print options. Make sure prin...

"-" not "_"
I wrote a SQL statement in the data tab. I wrote a bunch of alaises as example ' word-type ' but when I hit the layout tab it converts the "-" to "_". So now my field name is ' word_type '. Is there any way to prevent this? CardGunner Don' use a hypen ( - ).  It isn't a valid character for column names.   See http://searchsqlserver.techtarget.com/expert/KnowledgebaseAnswer/0,289625,sid87_gci1188931,00.html   Here's an excerpt about column names: Letters as defined in the Unicode Standard 2.0 Decimal numbers from either B...

Replacing "\\" with "\"
Hi all I'm getting this value from a CheckBoxList control - a location of file, i have to remove "\\" and replace it with "\" and pass it to Query, how to do it, i tried with Replace, but coud'nt suceed. "\\\\Blaze10xp\\BLZ_SFS_07\\Sample Excel Files\\Excel Files\\report2.xls" thank's in advance - Prakash.C you tried Replace like this? string newstring = oldstring.Replace(@"\\",@"\");Plese, do not forget to click "Mark as Answer" on the post that helped you. Thanx!My blog: Scenes From A Developer Memory yes i tr...

"Me" is better than "You"
Yes I know, strings are frozen. But let me talk about it, I really can't get through the idea of a PC talkin to me. I consider my PC as an extension of myself, not a dumb companion who addresses Me as You. Yes there are times when I get angry with Him while I work and get wrong calculations etc.., but it really is my fault, Me using wrong istructions and eventually wanting to find someone else to blame, but it's Me. And yes, I consider Thunderbird my mail program, reading my mail on my PC as Me. So I personally like to have Me in the header bar as a compact address ...

Using "+" or "||"
Using SQLAnywhere 5.5.04, I've gotten into the habit of using "||" in ISQL to indicate a string concatenation. I needed to paste my SQL statement into the PowerBuilder script painter for some embedded SQL, and PB didn't like the "||" very much at all. I changed it to "+" and it seems to be ok. Do these two operators indicate ~exactly~ the same thing? moin, afaik these two's are not the same! if you're using "||" and any term is NULL then in the resultstring the term will be ignored if you use "+" then the resu...

Web resources about - Paging Repeater treating page 11 as "1" and "1" not "11" - asp.net.presentation-controls

Resources last updated: 12/21/2015 10:32:16 AM