This is probably an easy solution but I can’t get my head around it.
I have pages that are dynamically generated, and I count the pages that need to be generated via a LINQ statement (e.g.): (THIS IS UPDATED CODE to show where the questionCount is called and set to _labelQuestionCount – this is a snippet from a larger method that dynamicaly generated all pages and set all controls in dynamic pages)
using (DataClasses1DataContext db = new DataClasses1DataContext())
{
int questionsCount = (from q in db.vw_Custom_SelectQuestionnaireQuestions
select q.tbl_QuestionnaireQuestion_Description).Count();
_labelQuestionCount = questionsCount.ToString();
}
Label labelCount = new Label();
labelCount.ForeColor = Color.Blue;
labelCount.Location = new System.Drawing.Point(35, 290);
labelCount.Size = new System.Drawing.Size(150, 30);
labelCount.Tag = _dataSetRadioButtons.Tables["tbl_QuestionnaireAnswer_Score"];
labelCount.Text = String.Format("Question Count: {0}", _labelQuestionCount);
Here is the global var:
string _labelQuestionCount;
The reason for this is, as I click through the dynamically created pages, I would like to “count” them so that in my “next button” event I will know the x page is my final page and I can navigate/do some other code.
Current code for next button is: (UPdated)
void nextButton_Click(object sender, EventArgs e)
{
bool c = IsChecked(_form);
if (c == true)
{
var w = Convert.ToInt32(_labelQuestionCount);
_form.Dispose();
w--;
if (w == 0)
{
//go to another page or do something else
}
}
else
{
MessageBox.Show("You must select at least one.");
}
}
As you can see I try and the the value from a global variable (e.g. __labelQuestionCount) and try and count it “down” until get to 0 and do something else.
But, because my pages are dynamically generated, I never get to 0.
This is probably the wrong way to go about this, so if anyone could suggest or help it would be greatly appreciated.
Kind regards,
geoNeo
you have to reassign the decreased value(w–) to global variable _labelQuestionCount inside next button click event. because if you click on next the _labelQuestionCount will be remain same for all click.