我有一个正在编写的 ASP.NET C# 调查程序。我有 56 个不同的下拉列表控件要映射到 56 个标签控件。我不想通过传统方式列出它:
lblSummary1.Text = DropDownList1.SelectedValue;
lblSummary2.Text = DropDownList2.SelectedValue;
lblSummary3.Text = DropDownList3.SelectedValue;
.
.
lblSummary56.Text = DropDownList56.SelectedValue;
所以我决定像这样以编程方式编写它:
// Map all the dropDown Selected Data to the their Various Labels
string mylbl = "lblSummary";
string myddl = "DropDownList";
int counter;
int totalAnswers = 57;
for (counter = 1; counter < totalAnswers; counter++ )
{
mylbl += counter.ToString() + "." + "Text;<br/>";
myddl += counter.ToString() + "." + "Text;<br/>";
mylbl = myddl;
}
为了查看输出,我将答案映射到如下标签:
lblSummary57.Text = myddl;
这是我得到的结果是
DropDownList1.Text;
2.Text;
3.Text;
4.Text;
5.Text;
6.Text;
7.Text;
8.Text;
.
.
.
56.Text;
请帮助我,我是 ASP.NET 的新手
谢谢你。