【发布时间】:2014-02-17 05:14:58
【问题描述】:
我的页面加载中有代码背后的代码,它设置了一个下拉列表文本和值。当我选择一个值时,它会重新加载页面,因为我有自动回帖。即使在回发后,我也需要保持选中的值。我该怎么做呢?以下是我的代码:
protected void Page_Load(object sender, EventArgs e)
{
List<string> list = new List<string>
{ "Month", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"};
DropDownListMonth.DataSource = list;
DropDownListMonth.DataBind();
DropDownListMonth.SelectedIndex = 0;
foreach (ListItem item in DropDownListMonth.Items)
{
int i = 0;
string month = Convert.ToString(i);
item.Value = month;
i = Convert.ToInt32(month);
i++;
}
}
【问题讨论】:
-
如果任何答案解决了您的问题,您应该点击旁边的复选标记接受它。
标签: c# asp.net drop-down-menu code-behind