Click here to Skip to main content
12,063,452 members (73,690 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: event DropDownList
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.
Posted 3-Feb-13 20:59pm
Comments
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.

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 | Mobile
Web01 | 2.8.160204.4 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2016
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