Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:-
XML
<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.
Posted
Updated 2-Dec-16 19:13pm
Comments
Jameel VM 4-Feb-13 5:22am    
you have placed two dropdown with same id. Please give a unique Id to the controls.
rrjoshi2321992 4-Feb-13 5:30am    
no its different..there is a diference of "s"
1st ID is "selectcategorydd"
2nd ID is "select's'categorydd"
Jameel VM 4-Feb-13 5:35am    
did you validate any controls while dropdown change?
rrjoshi2321992 4-Feb-13 5:58am    
nop i m not validating any control in dropdown index change.

1 solution

Remove selectscategorydd.DataValueField = "SubCategoryID"; this line and try or make DataValueField to SubCategoryName.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900