本文介绍了DropdownList SelectedIndexChanged事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我填充了子类别下拉列表下拉列表。 但是当我在类别下拉列表中更改类别时,其SelectedIndexChanged事件未触发。我的代码是: - 加价: - < td > < asp:DropDownList ID = selectcategorydd runat = server class = styledselect_form_1 AutoPostBack = true AppendDataBoundItems = True onselectedindexchanged = selectcategorydd_SelectedIndexChanged > < / asp:DropDownList > < / td > < td > < asp:RequiredFieldValidator ID = rfvc runat = server Contro lToValidate = selectcategorydd ForeColor = 红色 ErrorMessage = 选择类别 > * < / asp:RequiredFieldValidator > < / td > < / tr > < tr > < th valign = top > 子类别:< / th > < td style = width:30% > < asp:DropDownList ID = choicescategorydd runat = server AutoPostBack = true AppendDataBoundItems = True class = styledselect_form_1 > < / asp:DropDownList > CodeBehind: protected void Fill_Category() { DataTable categorytbl = d.fill_category(); selectcategorydd.DataSource = categorytbl; selectcategorydd.DataTextField =CategoryName; selectcategorydd.DataValueField =CategoryID; selectcategorydd.DataBind(); selectcategorydd.Items.Insert(0, - Select--); } protected void selectcategorydd_SelectedIndexChanged(object sender,EventArgs e) { int catid = int.Parse(selectcategorydd.SelectedValue ); DataTable t1 = d.cascadesubcat(catid); choosecategorydd.DataSource = t1; chosencategorydd.DataTextField =SubCategoryName; chosencategorydd.DataValueField =SubCategoryID; choosecategorydd.DataBind(); choosecategorydd.Items.Insert(0, - Select--); } 注意: - viewstate在页面指令中也是如此。解决方案 删除choicescategorydd.DataValueField =SubCategoryID;这一行并尝试将DataValueField设为SubCategoryName。 I m populating subcategory dropdown fom category dropdown.but when i change category in category dropdown its "SelectedIndexChanged"event is not firing.here is my code:-Markup:-<td><asp:DropDownList ID="selectcategorydd" runat="server" class="styledselect_form_1" AutoPostBack="true" AppendDataBoundItems="True" onselectedindexchanged="selectcategorydd_SelectedIndexChanged"></asp:DropDownList> </td> <td> <asp:RequiredFieldValidator ID="rfvc" runat="server" ControlToValidate="selectcategorydd" ForeColor="Red" ErrorMessage="Select category">*</asp:RequiredFieldValidator> </td> </tr> <tr> <th valign="top" > SubCategory:</th> <td style="width:30%"> <asp:DropDownList ID="selectscategorydd" runat="server" AutoPostBack="true" AppendDataBoundItems="True" class="styledselect_form_1"></asp:DropDownList>CodeBehind:protected void Fill_Category() { DataTable categorytbl = d.fill_category(); selectcategorydd.DataSource = categorytbl; selectcategorydd.DataTextField = "CategoryName"; selectcategorydd.DataValueField = "CategoryID"; selectcategorydd.DataBind(); selectcategorydd.Items.Insert(0, "--Select--"); } protected void selectcategorydd_SelectedIndexChanged(object sender, EventArgs e) { int catid = int.Parse(selectcategorydd.SelectedValue); DataTable t1 = d.cascadesubcat(catid); selectscategorydd.DataSource = t1; selectscategorydd.DataTextField = "SubCategoryName"; selectscategorydd.DataValueField = "SubCategoryID"; selectscategorydd.DataBind(); selectscategorydd.Items.Insert(0, "--Select--"); }Note:- viewstate is also true in page directive. 解决方案 Remove selectscategorydd.DataValueField = "SubCategoryID"; this line and try or make DataValueField to SubCategoryName. 这篇关于DropdownList SelectedIndexChanged事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-18 02:21