ASP:列表框值在回发时不可用
本文关键字:列表 ASP | 更新日期: 2023-09-27 18:30:19
大家好,我有一个asp:listbox,我在页面加载时从我循环访问并添加项目的数组填充它。 但是,提交表单时,值始终为空。我在表单中添加了另一个值
<asp:ListItem Value="blar" Text="blar"></asp:ListItem>
如果我选择该值,它会在回发中存在。
下面是我的页面加载代码以填充列表框
foreach (string cntry in Countries.CountriesArray())
{
YrCountrySelect.Items.Add(new ListItem(cntry, cntry));
if (Page.IsPostBack && YrCountrySelect.SelectedValue == cntry) YrCountrySelect.SelectedValue = cntry;
}
有谁知道为什么它不传递所选值???
仅在
第一页加载时绑定回发
if(!IsPostBack)
{
//bind your listbox here
}
SortedDictionary<string, string> objDic = new SortedDictionary<string, string>();
foreach (CultureInfo ObjectCultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo objRegionInfo = new RegionInfo(ObjectCultureInfo.Name);
if (!objDic.ContainsKey(objRegionInfo.EnglishName))
{
objDic.Add(objRegionInfo.EnglishName, ObjectCultureInfo.Name);
}
}
foreach (KeyValuePair<string, string> val in objDic)
{
country.Items.Add(new ListItem(val.Key, val.Value));//country is dropdownlist name..
}