Ashish
Ashish

Reputation: 107

dropdown onselectingindexchanging doesnot trigger

I am working on a project and i am doing popup and in popup,when i popup the data from the grid get filled into the textbox/dropdown but what is happening is i have a dropdown of category and another dropdown as subcategory,what i want is when i select the category the subcategory related to category get filled in subcategory dropdown but what is happening is all the subcategory is getting filled up automatically.

<table class="panel_table">
<tr style="background-color:#0095E4">
<td colspan="2"><span class="panel_heading1">Category Details</span></td></tr>

<tr class="row1">
<td  colspan="2">
<span  class="paneltb_column1">BookID--</span>
<asp:Label ID="lblEditbookID" runat="server" Text="book ID"></asp:Label></td>
</tr>

<tr class="row1" >
<td colspan="2">
<span  class="paneltb_column2">Book Name</span>
<asp:TextBox CssClass="txtbox1"  ID="txtEditbookname" runat="server"></asp:TextBox>
</td></tr>

<tr class="row1" >
<td colspan="2">
<span  class="paneltb_column2">Category Name</span> 

<asp:DropDownList ID="drp_editcatname" runat="server" Width="120px"
   AutoPostBack="true"        OnSelectedIndexChanged="drpeditgetvaluesubcategory_onselectinindexchange">       </asp:DropDownList>
 </td></tr>

 <tr class="row1">
 <td colspan="2">
 <span  class="paneltb_column2">SubCategory Name</span>
 <asp:DropDownList ID="drpEditsubcatname" CssClass="txtbox2" 
  runat="server">               </asp:DropDownList>
 </td>
 </tr>
 <tr class="row1" >
 <td colspan="2">
 <span  class="paneltb_column2">Author Name</span>
 <asp:DropDownList ID="drp_editauthorname" runat="server"></asp:DropDownList>
 </td>
 </tr>
  </table> 

code behind

 protected void drpgetvaluesubcategory_onselectedindexchange(object sender,EventArgs e)
 {

   sql = "select subcat_id,subcategoryname from library_subcategory where    cat_id='"+drp_categoryname.SelectedItem.Value+"'";
   ds = obj.openDataset(sql, Session["SCHOOLCODE"].ToString());
    drp_subcategoryname.Items.Clear();  
    ListItem li = new ListItem();
    li.Text = "Select SubCategory";
    li.Value = "0";
    drp_subcategoryname.Items.Add(li);
    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
    {

        li = new ListItem();
        li.Text = ds.Tables[0].Rows[i]["subcategoryname"].ToString();
        li.Value = ds.Tables[0].Rows[i]["subcat_id"].ToString();
        drp_subcategoryname.Items.Add(li);
    }
}

Upvotes: 0

Views: 97

Answers (1)

Damith
Damith

Reputation: 63065

check name of the event correctly put on aspx or not,

 OnSelectedIndexChanged="drpeditgetvaluesubcategory_
     onselectinindexchange"

is there any space between two words? event name is different as in code behind

you need to correct it as

 OnSelectedIndexChanged="drpgetvaluesubcategory_onselectedindexchange"

and event name should be drpgetvaluesubcategory_onselectedindexchange

Upvotes: 1

Related Questions