我试图通过一系列查询来填充我的下拉菜单,我会在页面加载时自动进行查询。每当我选择在下拉列表中选择价值,我按下一个按钮,它可以追溯到第一指标,所以我想知道是否有无论如何要防止出现此问题:在页面加载中填充DropDown
protected void Page_Load(object sender, EventArgs e)
{
Functions.username = "1"; // This is just to get rid of my login screen for testing puposes
DropDownList1.Items.Clear();
Functions.moduledatelister();
for (int i = 0; i <= Functions.moduledatelist.Count-1; i++) {
DropDownList1.Items.Add(Functions.moduledatelist.ElementAt(i));
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = Functions.DATES.ElementAt(DropDownList1.SelectedIndex).ToString();
}
按下按钮后索引回到0,标签显示第一个项目的值。
非常感谢你:) –