为什么在DropDownList上更改选择时未触发事件? [英] Why event not fired when I change selection on DropDownList?

查看:60
本文介绍了为什么在DropDownList上更改选择时未触发事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个asp net drp框:

I have this asp net drp box:

<asp:DropDownList ID="ddlLayersList"
        runat="server"
        BackColor="#FFFFC0"
        CssClass="form-control fullwidth" OnTextChanged="ddlLayersList_SelectedIndexChanged" >
</asp:DropDownList>

这是我填写投递箱的方式:

Here is how I fill the drop box:

private void SetLayers(Dictionary<string, string> layers)
{
    ddlLayersList.DataSource = layers;
    ddlLayersList.DataValueField = "Key";
    ddlLayersList.DataTextField = "Value";
    ddlLayersList.DataBind();
    ddlLayersList.Items.Insert(0, "-Select Item-");
}

这是事件背后的代码:

protected void ddlLayersList_SelectedIndexChanged(object sender, EventArgs e)
{
}       

当我从下拉框中选择项目时,事件未触发.我在 DropDownList 上更改选择时为什么不触发事件?

When I select item from drop box the event not fired. Any idea why event not fired when I change selection on DropDownList?

推荐答案

您需要设置

You need to set the AutoPostBack property to True.

<asp:DropDownList ID="ddlLayersList" AutoPostBack="True">

此属性的值:

true,如果每当用户更改列表的选择;否则为假.默认值是错误的

true if a postback to the server automatically occurs whenever the user changes the selection of the list; otherwise, false. The default is false

此外,您还需要设置

Also you need to set the OnSelectedIndexChanged event instead of OnTextChanged:

<asp:DropDownList ID="ddlLayersList" 
       AutoPostBack="true" runat="server" 
       OnSelectedIndexChanged="ddlLayersList_SelectedIndexChanged">

这篇关于为什么在DropDownList上更改选择时未触发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆