我创建了一个ASP.NET网站。我的目的是根据下拉列表中选择的项目使标签内容发生更改。我尝试了以下方法,但未成功:
下拉列表如下:
<asp:DropDownList ID="DropDown1" runat="server" >
<asp:ListItem Value="a"></asp:ListItem>
<asp:ListItem Value="b"></asp:ListItem>
onselectedindexchanged="DropDown1_SelectedIndexChanged"
</asp:DropDownList>
标签:
<asp:Label ID="Label1" Text="" runat="server"/>
我希望不必使用PostBack来完成这个操作。
我尝试使用ajax Update Panel 来实现:
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="DropDown1" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" Text="" runat="server"/>
</ContentTemplate>
</asp:UpdatePanel>
在代码后台的DropDown1_SelectedIndexChanged事件中:
protected void DropDown1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = DropDown1.SelectedValue;
}
但这不起作用。
有人可以帮我解决吗?
非常感谢任何帮助。