Click here to Skip to main content
Rate this: bad
good
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 at 4-Feb-13 5:22am
   
you have placed two dropdown with same id. Please give a unique Id to the controls.
rrjoshi2321992 at 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 at 4-Feb-13 5:35am
   
did you validate any controls while dropdown change?
rrjoshi2321992 at 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
0 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 186
4 Aajmot Sk 153
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2014
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