DropDownList的SelectedIndexChanged()如何使用PostBack? [英] How DropDownList's SelectedIndexChanged() works without PostBack?
本文介绍了DropDownList的SelectedIndexChanged()如何使用PostBack?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
DropDownList的 SelectedIndexChanged()
事件填充页面上的ListBox。显然,这个页面将该页面发送回服务器。有没有什么办法可以实现没有完整的回发?
DropDownList's SelectedIndexChanged()
Event fills the ListBox on the page. Obviously this posts the page back to the server. Is there any way to make it happen without full postback?
protected void ddlTablo_SelectedIndexChanged(object sender, EventArgs e)
{
List<string> list = new List<string>();
ListBox1.Items.Clear();
var columnNames= from t in typeof(Person).GetProperties() select t.Name;
foreach (var item in columnNames)
{
list.Add(item);
}
ListBox1.DataSource = list;
ListBox.DataBind();
}
推荐答案
您可以将DropDownList在DropDownList上设置< asp:UpdatePanel>
并设置 AutoPostBack =true
您必须将触发器设置为 SelectedIndexChanged
事件。
You could put the DropDownList into an <asp:UpdatePanel>
and set AutoPostBack="true"
on the DropDownList. You have to set the trigger to the SelectedIndexChanged
event.
这样的事情(不要忘记脚本管理器)
Something like this (don't forget the script manager)
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="drop1" runat="server" OnSelectedIndexChanged="ddlTablo_SelectedIndexChanged" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostbackTrigger ControlID="drop1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
这篇关于DropDownList的SelectedIndexChanged()如何使用PostBack?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文