Jud*_*ude 6 asp.net postback drop-down-menu
DropDownList的SelectedIndexChanged()事件填充页面上的ListBox.显然,这会将页面发布回服务器.有没有办法在没有完全回发的情况下实现它?
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();
}
Run Code Online (Sandbox Code Playgroud)
您可以将DropDownList放入<asp:UpdatePanel>并设置AutoPostBack="true"DropDownList.您必须将触发器设置为SelectedIndexChanged事件.
像这样的东西(不要忘记脚本管理器)
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29295 次 |
| 最近记录: |