下拉列表选择的IndexChanged未触发

时间:2013-12-21 10:56:43

标签: asp.net

我有一个下拉列表,其autopostback属性设置为true。但是当更改值时,不会触发selectedindexchanged属性,而是总是要进行pageload.Please告诉问题是什么。

<asp:DropDownList ID="ddlVendor" CssClass="ddl" runat="server"
    OnSelectedIndexChanged="ddlVendor_SelectedIndexChanged" AutoPostBack="true">


protected void ddlVendor_SelectedIndexChanged(object sender, EventArgs e)
{
    List<ProcurementItem> vendorsList = new List<ProcurementItem>();
    vendorsList = (List<ProcurementItem>)ViewState["VendorList"];
    string ID = string.Empty;
    string accountID = string.Empty;
    int? accountType = null;
    if (ddlVendor.SelectedIndex > 0)
    {
        ID = ddlVendor.SelectedValue;


        ProcurementClient procurementClient = new ProcurementClient();

        List<ProcurementContract> contractList =    
       procurementClient.GetContractList(Convert.ToInt32(ID), null);
        contractList = contractList.Where(i => i.Status == 4).ToList();
        ddlContracts.DataSource = contractList;
        ddlContracts.DataTextField = "ContractIDName";
        ddlContracts.DataValueField = "ContractID";
        ddlContracts.DataBind();
        ddlContracts.Items.Insert(0, "");
    }

}

4 个答案:

答案 0 :(得分:0)

试试这个

<asp:dropdownlist id=ddltrim width="100%" Runat="server" AutoPostBack="True" EnableViewState="True" onselectedindexchanged="ddltrim_SelectedIndexChanged">

确保你的DropDownList在Fom标签中

<form>

//

</form>

答案 1 :(得分:0)

亲爱的检查causevalidation = false

可能是这个问题 如果你的页面有任何验证,亲爱的

谢谢

:d

答案 2 :(得分:0)

如果要填充数据库中的下拉列表,请确保只有当它不是一个帖子后才会调用下拉列表的DataBind()方法...

protected void Page_Load(object sender, EventArgs e)
{
...
       If(!Page.IsPostBack)
       {
             ......
             dropdownlist.DataBind();
             .....
       }
...
}

希望这会有所帮助:)

答案 3 :(得分:0)

DropDownList

中添加以下属性

1的 ViewStateMode = “启用”

2. EnableViewState =“true”

3. AutoPostBack =“true”