dropdown selectedindexchanged不会触发

时间:2013-04-22 11:27:58

标签: c# asp.net ajax

我正在开发一个项目,我正在进行弹出窗口和弹出窗口,当我弹出数据从网格中填入文本框/下拉列表但发生的事情是我有一个类别的下拉列表和另一个下拉列表作为子类别,我想要的是当我选择类别时,与子类别相关的子类别在子类别下拉列表中填充,但发生的事情是所有子类别都自动填满。

<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> 

背后的代码

 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);
    }
}

1 个答案:

答案 0 :(得分:1)

检查正确放入aspx的事件名称,

 OnSelectedIndexChanged="drpeditgetvaluesubcategory_
     onselectinindexchange"

两个单词之间有空格吗?事件名称与后面的代码不同,

您需要将其更正为

 OnSelectedIndexChanged="drpgetvaluesubcategory_onselectedindexchange"

且事件名称应为drpgetvaluesubcategory_onselectedindexchange