【发布时间】:2013-01-08 19:03:50
【问题描述】:
我的asp.net面板有问题我想在更改另一个下拉框的索引时修改下拉框数据源选择命令,但每次我更改新的下拉框都会创建 这是我的代码:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:DropDownList ID="comboCountry" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource3" OnSelectedIndexChanged="comboCountry_OnSelectedIndexChanged"
DataTextField="country_name" DataValueField="country_id">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:JobsConnectionString %>"
SelectCommand="SELECT * FROM [country]"></asp:SqlDataSource>
</td>
</tr>
<tr class="trwidth">
<td>
<asp:DropDownList ID="comboCity" runat="server" DataSourceID="SqlDataSource2"
DataTextField="city_name" DataValueField="location_id">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:JobsConnectionString %>"
SelectCommand="SELECT * FROM [location]"></asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
后面的代码:
protected void comboCountry_OnSelectedIndexChanged(object sender, EventArgs e)
{
try
{
SqlDataSource2.SelectCommand = "SELECT * FROM [location] where [country_id]=" + comboCountry.SelectedValue;
// SqlDataSource2.DataBind();
comboCity.DataBind();
}
catch (Exception exception)
{
Debug.WriteLine(exception.Message);
}
}
【问题讨论】:
-
您能详细解释一下问题所在吗?你得到什么结果,你想要什么结果?
-
当我更改组合框 (comboCountry) 的索引时,它应该调用方法 comboCountry_OnSelectedIndexChanged 并更改 SqlDataSource2 的数据源选择命令,然后应该更新组合框 (comboCity) 项目,而不是更新组合框 (comboCity) 项目获取包含新项目的新组合框。
-
“新项目”是什么意思?
-
我的意思是这个
标签: asp.net combobox updatepanel dropdownbox