简体   繁体   中英

call dropdownlist selected index changed event manually

i have a dropdown which fill on page load event.

private void FillSponsor()
    {
        ddlSponsor.DataSource = Db.VCT_SPONSORs.Where(x => x.IS_ACTIVE.GetValueOrDefault() && x.IS_APPROVED.GetValueOrDefault());
        ddlSponsor.DataBind();
    }

Now what i want is to bind other dropdown with the first value of above dropdown. my second dropdown is:

protected void ddlSponsor_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddlDivision.DataSource = Db.VCT_SPONSOR_DIVISIONs.Where(x => x.SPONSOR_ID==SponsorID);
        ddlDivision.DataBind();
        ddlDivision.Items.Insert(0, new ListItem("All", "0"));
    }

My problem is how to call ddlSponsor_SelectedIndexChanged event from the FillSponsor method. My both dropdowns are in update panels.

你的意思是你怎么称呼这个方法?

ddlSponsor_SelectedIndexChanged(this, EventArgs.Empty);

You can use DateBound Event instead. like...

protected void ddlSponsor_DataBound(object sender, EventArgs e)
{
    ddlDivision.DataSource = Db.VCT_SPONSOR_DIVISIONs.Where(x => x.SPONSOR_ID==SponsorID);
    ddlDivision.DataBind();
    ddlDivision.Items.Insert(0, new ListItem("All", "0"));
}

I believe your main problem is having controls in separate update panels.

http://forums.asp.net/t/1426233.aspx

Code sample from that link:

<asp:UpdatePanel runat="server" ID='asdsd' UpdateMode="Conditional">
 <ContentTemplate>
    ...DropDownList1...
</ContentTemplate>

<Triggers>
    <asp:AsyncPostBackTrigger ControlID='DropDownList2' EventName='SelectedIndexChanged' />
</Triggers>

I believe what you are after is AsyncPostBackTriggers, and don't forget UpdateMode="Conditional".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM