DropDownList控件的前台动作
<asp:DropDownList ID="DropDownList4" runat="server" AutoPostBack="True"
Width="140px" onselectedindexchanged="DropDownList4_SelectedIndexChanged">
</asp:DropDownList>
使用 选择索引的改变事件 AutoPostBack 自动回发
后台a.aspx.cs
protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
{
//处理你的内容
}
我是想在前台进行动作
可以使用onchange事件 DropDownList控件本质就是select option
参考如下代码:(年月日下拉的设置)
//a.aspx代码
自<asp:DropDownList ID="ddlYearBegin" runat="server" Width="50px" onchange="onChangeEvent('ddlYearBegin','ddlMonthBegin','ddlDayBegin');"></asp:DropDownList>年<asp:DropDownList
ID="ddlMonthBegin" runat="server" Width="40px" onchange="onChangeEvent('ddlYearBegin','ddlMonthBegin','ddlDayBegin');"></asp:DropDownList>月
<asp:DropDownList ID="ddlDayBegin" runat="server" Width="40px"></asp:DropDownList>日<asp:DropDownList
ID="ddlHourBegin" runat="server"
js:
function OperSelect(idStr, maxDay) {//操作select option
var obj = document.getElementById(idStr);
obj.options.length = 0; //清空select的项
for (var i = 1; i <= maxDay; i++) { //增加天数为1到[28,29,30,31]天
var varItem = new Option(i, i);
obj.options.add(varItem);
}
}