我想使用 Javascript 将项目添加到 ASP.Net 组合框。我可以检索 ID(无主页)。如何从 Javascript 向组合框添加值?我现在的代码如下所示。
//Fill the years (counting 100 from the first)
function fillvarYear() {
var dt = $('#txtBDate').val();
dt = dt.toString().substring(6);
var ye = parseInt(dt);
//Loop and add the next 100 years from the birth year to the combo
for (var j = 1; j <= 100; j++) {
ye += 1; //Add one year to the year count
var opt = document.createElement("OPTION");
opt.text = ye;
opt.value = ye;
document.form1.ddlYear.add(opt);
}
}
最佳答案
查看回传值:
string selectedValue = Request.Params[combobox.UniqueId]
请记住,使用 javascript 更改组合框中的值将导致抛出事件验证异常,这通常是一个坏主意,因为您必须明确禁用事件验证。
我建议将组合框放在更新面板中,这样您就可以在服务器上读取 txtBirthDate 并生成适当的数据。然后您也不必手动保留状态。
关于asp.net - 我想使用 Javascript 将项目添加到 ASP.Net 组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/280229/