如何从javascript重置下拉列表选择索引服务器端值?

时间:2011-05-11 07:30:57

标签: javascript asp.net drop-down-menu

问题是我有一个date文本框和一个shifts下拉列表。当我选择日期和班次时,我会得到员工名单。下拉列表中有onSelectedIndexChanged个事件,因此只有在我们更改班次时才会填充员工列表。所以对于日期chage,我添加了一个javascript来重置shift dropdown0索引。因此,每当您更改日期时,您也必须选择班次,并且将触发selectindex change事件。 the problem is when I reset shifts dropdown from javascript it is done only in client side not in server side.So if I select dropdownt to the previous value it doesn't fire the change event but for other values it works fine

<asp:TextBox ID="txtSelectDate" runat="server" CssClass="inputAddRes" onchange="javascript:return ResetShifts();"></asp:TextBox>  

<asp:DropDownList ID="ddlShifts" AutoPostBack="true" OnSelectedIndexChanged="ddlShifts_SelectedIndexChanged"                                     runat="server" >
<asp:ListItem Text="Morning" Value="1"/>
<asp:ListItem Text="Evening" Value="2"/>
<asp:ListItem Text="Night" Value="3"/>
</asp:DropDownList>

function ResetShifts() {
        document.getElementById('<%= ddlShifts.ClientID %>').selectedIndex = 0;
        }

1 个答案:

答案 0 :(得分:0)

您可以手动调用select onchange事件

 document.getElementById('<%= ddlShifts.ClientID %>').onchange();