0

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

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

1 回答 1

1

检查是否正确放置在 aspx 上的事件名称,

 OnSelectedIndexChanged="drpeditgetvaluesubcategory_
     onselectinindexchange"

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

您需要将其更正为

 OnSelectedIndexChanged="drpgetvaluesubcategory_onselectedindexchange"

和事件名称应该是drpgetvaluesubcategory_onselectedindexchange

于 2013-04-22T11:34:20.667 回答