1

i have three dropdownlists with autopostaback=true,but the problem is that for second dropdownlist only pageload is called but it's selectedindexchanged is not firing! what can i do?(dropdownlists are in updatepanel )

EDIT:
 protected void Page_Load(object sender, EventArgs e)
    {
        if (DDL_d1.Items.Count == 0)
        {
            SqlDataReader dr = null;
            DbAccessor db = new DbAccessor();
            dr = db.SqlSelectS("true", "SELECT Fname FROM [Tbl_Amoozesh]");
            DDL_d1.Items.Clear();
            while (dr.Read())
                DDL_d1.Items.Add(dr[0].ToString());
            db.Dispose();
        }
    }
    protected void d1(object sender, EventArgs e)
    {

        DDL_d1.AutoPostBack = false;
        SqlDataReader dr = null;
        DbAccessor db = new DbAccessor();
        dr = db.SqlSelectS(DDL_d1.SelectedValue,"SELECT Fname FROM [Tbl_Amoozesh] where Fname = @a");
        DDL_d2.Items.Clear();
        DDL_d2.Items.Add(new ListItem("hi"));
        while (dr.Read())
            DDL_d2.Items.Add(dr[0].ToString());
        db.Dispose();




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

        SqlDataReader dr = null;
        DbAccessor db = new DbAccessor();
        dr = db.SqlSelectS(DDL_d2.SelectedValue, "SELECT Lname FROM [Tbl_Amoozesh] where Fname = @a");
        DDL_d3.Items.Clear();
        while (dr.Read())
            DDL_d3.Items.Add(dr[0].ToString());
        db.Dispose();

    }
2
  • 1
    Do you have any DataBind calls on Load? remove those. DataBinds should happen only on the first request when IsPostBack is false. Feb 24, 2013 at 12:28
  • Post your code please Feb 24, 2013 at 12:43

2 Answers 2

2

You have to put an asynchronous trigger in your updatepanel. Try this:

<asp:UpdatePanel id="up1" runat="server" updatemode="conditional">
   <Triggers>
      <asp:AsyncPostBackTrigger ControlID="ddl" EventName="SelectedIndexChanged" />
   </Triggers>
   <ContentTemplate>
      <%-- your content here --%>
      <asp:DropdownList id="ddl" AutoPostback="true" OnSelectedIndexChanged="handler" />
   </ContentTemplate>
</asp:UpdatePanel>
1
  • but there is a problem for last parameter SelectedIndexChanged not fired(only once is firing) for other elements is ok
    – Mahdi_Nine
    Feb 24, 2013 at 15:06
0

I recently had the same problem. I was also populating my dropdownlist from a database table and I tried everything including setting AutoPostBack = true on the control. It turns out this is a known bug that you can resolve by making index 0 a dummy item like 'Select a person'. Check out the post here:

https://forums.asp.net/t/1275349.aspx?Dropdownlist+not+firing+SelectedIndexChanged+on+first+item+with+autopostback+true

This solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.