我有一个asp.net面板的问题,我想修改一个dropdownbox数据源create命令,当我更改其他dropdownbox的索引时,但每次我更改新的dropdownbox时,创建以下代码:
<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);
}
}发布于 2013-01-09 04:48:57
在第一个dropdown中选择country_code的值,然后将第二个dropdown参数绑定到第一个dropdown。然后将第一个下拉列表的auto post设置回true,第二个下拉列表将使用结果进行渲染。
https://stackoverflow.com/questions/14222190
复制相似问题