1

我有三个dropdownlistsautopostaback=true但问题是第二个dropdownlistpageload被调用,但它selectedindexchanged没有触发!我能做什么?(dropdownlistsupdatepanel

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();

    }
4

2 回答 2

1

您必须在更新面板中放置一个异步触发器。尝试这个:

<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>
于 2013-02-24T13:03:06.527 回答
0

我最近遇到了同样的问题。我还dropdownlist从数据库表中填充了我的内容,并尝试了所有内容,包括AutoPostBack = true控件上的设置。事实证明,这是一个已知错误,您可以通过将索引 0 设置为“选择人员”之类的虚拟项目来解决。看看这里的帖子:

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

这解决了我的问题。

于 2019-10-13T09:25:46.343 回答