![](/img/trans.png)
[英]How to count number of the textbox within a cell in a dynamically generated HTML Table using a JavaScript?
[英]Count the number of dynamically generated pages
这可能是一个简单的解决方案,但我无法解决。
我有动态生成的页面,并计算了需要通过LINQ语句生成的页面(例如):(此更新代码显示了在哪里调用questionCount并将其设置为_labelQuestionCount -这是来自较大代码段的摘录动态生成所有页面并在动态页面中设置所有控件的方法)
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);
这是全局变量:
string _labelQuestionCount;
原因是,当我单击动态创建的页面时,我想对其进行“计数”,以便在我的“下一个按钮”事件中,我将知道x页面是我的最终页面,并且我可以导航/执行其他操作码。
下一个按钮的当前代码为:(已更新)
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.");
}
}
如您所见,我尝试使用全局变量(例如__labelQuestionCount
)中的值,并尝试对其进行“递减”计数直至达到0并执行其他操作。
但是,因为我的页面是动态生成的,所以我永远都不会达到0。
这可能是错误的解决方法,因此,如果有人可以提出建议或提供帮助,将不胜感激。
亲切的问候,geoNeo
您必须在下一个按钮单击事件内将减小的值(w--)重新分配给全局变量_labelQuestionCount。 因为如果您单击下一步,则_labelQuestionCount对于所有单击将保持不变。
我会考虑为Page
分配一些int PageID
,如果还没有的话。 而且,当您从基础中恢复页面的集合时,您无需计算它们的数量,而是获得现在可用的最新页面的PageID
。
在button_click
您在单击时再次询问大学中的最后一个元素(因为它可能已更改,新页面已添加到大学中),重新命名其PageID
,并检查您要摆动的页面是否具有相同的ID,如果是,请执行所需的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.