Click here to Skip to main content
13,202,873 members (56,484 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I m populating subcategory dropdown fom category dropdown.
but when i change category in category dropdown its "SelectedIndexChanged"event is not is my code:-

<td><asp:DropDownList ID="selectcategorydd" runat="server"
                class="styledselect_form_1" AutoPostBack="true"
            <asp:RequiredFieldValidator ID="rfvc" runat="server"
                ControlToValidate="selectcategorydd"  ForeColor="Red" ErrorMessage="Select category">*</asp:RequiredFieldValidator>
        <th valign="top" > SubCategory:</th>
        <td style="width:30%">
            <asp:DropDownList ID="selectscategorydd" runat="server" AutoPostBack="true" AppendDataBoundItems="True"

 protected void Fill_Category()
            DataTable categorytbl = d.fill_category();
            selectcategorydd.DataSource = categorytbl;
            selectcategorydd.DataTextField = "CategoryName";
            selectcategorydd.DataValueField = "CategoryID";
            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.Items.Insert(0, "--Select--");

Note:- viewstate is also true in page directive.
Posted 3-Feb-13 19:59pm
Updated 2-Dec-16 19:13pm
JemiM 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"
JemiM 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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171020.1 | Last Updated 3 Dec 2016
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100