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