我在代码隐藏中有两个下拉列表和它们的隐藏字段,我通过 attribute.add 添加 javascript onchange 事件和一个按钮来执行一些动态操作,例如在运行时添加控件,当我单击该按钮时,下拉列表被重置。为了保持状态,我有一个带有下拉菜单的隐藏字段,我从隐藏字段中获取 selectedvalue 但通过编码 DDCity.Items.FindByValue 似乎不起作用有人能帮忙吗?
protected void Page_Load(object sender, EventArgs e)
{ DDCountry.Attributes.Add("onChange", "javascript:BufferAddDDCountry('" + DDCountry.ClientID + "');");
DDCity.Attributes.Add("onChange", "javascript:BufferAddDDCity('" + DDCity.ClientID + "');");}
if (hiddenDDCityValue.Text != "0")
{
DDCity.Items.FindByValue(hiddenDDCityValue.Text).Selected = true;// this dont work
}
if (!IsPostBack)
{ this.populateCountry();populateCity();}
javascript代码
<script type="text/javascript">
function BufferAddDDCountry(objDd) {
try {
var objHidden = document.getElementById('hiddenDDcountryValue');
objHidden.value = document.getElementById(objDd).value;
} catch (e) {
alert(e);
}
};
function BufferAddDDCity(objDd) {
try {
var objHidden = document.getElementById('hiddenDDCityValue');
objHidden.value = document.getElementById(objDd).value;
} catch (e) {
alert(e);
}
};
</script>