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...






Forums » .NET » .NET »

NextPrevious button in c#


Posted Date: 06 Nov 2009      Posted By: Naresh      Member Level: Silver     Points: 1   Responses: 2



Hi All,
c# windows application
In My Application i using two buttons next and previous buttons.
i am using static variable called index.It is Online Examination application(question and Multiple choice).when i click on Next button i am going to first question)initially index is zero i retrieving data from database and the then incrementing index.then if i click next i will go second question and index will be 2.
i using dataset rows start from 0 but in next button iam incrementing index to retrieve next question)

to go to previous question when i click on previous button i not able to go to previous question for the first click because index will be one more than the present question so if i click for second time it will go to the previous question.This Problem is only when i click previous button imediately after the next button or next button immediately after previus button.






Responses

Author: Naresh    06 Nov 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

Hi

This is My code

if (index <dsQuestion.Tables[0].Rows.Count)
{
lblQuestion.Text = dsQuestion.Tables[0].Rows[index]["QuestionSequenceNumber"].ToString() + ":" + dsQuestion.Tables[0].Rows[index]["QuestionText"].ToString();
questionId = Convert.ToInt32(dsQuestion.Tables[0].Rows[index]["QuestionID"].ToString());
index += 1;
CreateRadioButtons(questionId);
button2.Enabled = true;
}

Previous()
index -= 1;
//label3.Text = "Index " + index.ToString();

if (index >= 0 && index < dsQuestion.Tables[0].Rows.Count)
{

btnMarks.Enabled = false;
button2.Enabled = true;
lblQuestion.Text = dsQuestion.Tables[0].Rows[index]["QuestionSequenceNumber"].ToString() + ":" + dsQuestion.Tables[0].Rows[index]["QuestionText"].ToString();
questionId = Convert.ToInt32(dsQuestion.Tables[0].Rows[index]["QuestionID"].ToString());
CreateRadioButtons(questionId);

}



Author: Kirtan    08 Nov 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

You need to Use CurrencyManager to Handle this type of issues Bind the DataTable With Currency Manager and All Texboxes you are using

then

Simply call cr.Position +=1

and cr.Position -=1 to Next Previous

Kirtan Patel
-----------------------------------------------------
Master Of Computer Application(Sem-1)
Bachelore of Computer Application



Post Reply
You must Sign In to post a response.
Next : Custom serialization
Previous : How to display a progress bar while executing a long method or an update statement?
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use