Click here to Skip to main content
15,898,954 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C#
protected void next1_Click(object sender, EventArgs e)
    {
        if (inc != Maxrows)
        {
            inc++;
            Records();
            Label2.Text = inc.ToString();
            inc++;
        }
    }


I wish to use the above code so as to output the next record but it it only executes once. How can I go about it?

[Edit]Code block added, ASP.NET tag added[/Edit]
Posted
Updated 27-Mar-13 6:29am
v2
Comments
Richard C Bishop 27-Mar-13 12:34pm    
You will want to use a for loop or a foreach loop. I see that you are attempting to use an incrementer, but an if statement does not work like that. An if statement can be executed several times inside a loop, but does not act as a loop itself.
jkirkerx 27-Mar-13 13:49pm    
What are you trying to display, so I can get an idea.

Is it like a product database?

You click next and to to the next single product?

When you click next, an update panel makes a request for new html, and get updated without a full page request, or is it a full page request?
Sergey Alexandrovich Kryukov 27-Mar-13 15:25pm    
Please stop posting non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA

You should use a while/do while loop in order to sort this out.Also the code you have given is always displays the result in the same label.So you need to change that.In order to check the condition number of times you have to use any loop inside that.
 
Share this answer
 
Comments
jdanastasi 27-Mar-13 13:21pm    
I have a set of records to display using a next button. once the next button is clickeed it displays it in the same label. So far I am only displaying two the first on page load and the second on button clickl. though for test purposes I have 3 records
Hi,

Did you check the values of the "inc" and "Maxrows" when you are trying to execute more than once. Is your 'if' condition satisfied ?
 
Share this answer
 
This is a sample example for displaying values in loop..

C#
int a = 5;
       while (a < 10)
       {
           ListBox1.Items.Add(Convert.ToString(a));
           a++;
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900