我用了4个dropdownlist,4级联动,动态绑定上去的。
当选择后要把跟这4个dropdownlist相关的内容查询并显示出来,但是SelectedIndexChanged事件
无法触发,我在网上也搜索了很多这方面的问题都无法解决,但是我自己只用1个dropdownlist试了
下,发现只用一个dropdownlist时可以触发事件,但是用4级联动后就无法触发事件了。
请大家帮帮忙,看下是什么情况造成的,我的事件是在dropdownlist的属性,然后选择
SelectedIndexChanged双击的,并且也设置了AutoPostBack="True" ,事件里也加
了if(!page.ispostback)。

解决方案 »

  1.   

     <asp:DropDownList ID="DropDownList1" Width="120px" runat="server" AutoPostBack="True">
                                                                                                        <asp:ListItem Selected="True">请选择产地</asp:ListItem>
                                                                                                        <asp:ListItem>国产汽车</asp:ListItem>
                                                                                                        <asp:ListItem>进口汽车</asp:ListItem>
                                                                                                    </asp:DropDownList>
                                                                                                    <asp:DropDownList ID="DropDownList2" Width="120px" runat="server" AutoPostBack="True"
                                                                                                        DataSourceID="SqlDataSource1" DataTextField="chinese" DataValueField="chinese">
                                                                                                    </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:521che_comConnectionString %>"
                                                                                                        SelectCommand="SELECT [chinese], [chandi] FROM [t_cars_brand] WHERE ([chandi] = @chandi)">
                                                                                                        <SelectParameters>
                                                                                                            <asp:ControlParameter ControlID="DropDownList1" DefaultValue="null" Name="chandi"
                                                                                                                PropertyName="SelectedValue" Type="String" />
                                                                                                        </SelectParameters>
                                                                                                    </asp:SqlDataSource>
                                                                                                    <asp:DropDownList ID="DropDownList3" Width="120px" runat="server" AutoPostBack="True"
                                                                                                        DataSourceID="SqlDataSource2" DataTextField="cartype" DataValueField="cartype">
                                                                                                    </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:521che_comConnectionString %>"
                                                                                                        SelectCommand="SELECT [pinpai], [chandi], [cartype] FROM [t_cars_type] WHERE (([pinpai] = @pinpai) AND ([chandi] = @chandi))">
                                                                                                        <SelectParameters>
                                                                                                            <asp:ControlParameter ControlID="DropDownList2" Name="pinpai" PropertyName="SelectedValue"
                                                                                                                Type="String" />
                                                                                                            <asp:ControlParameter ControlID="DropDownList1" Name="chandi" PropertyName="SelectedValue"
                                                                                                                Type="String" />
                                                                                                        </SelectParameters>
                                                                                                    </asp:SqlDataSource>
                                                                                                    <asp:DropDownList ID="DropDownList4" Width="120px" runat="server" DataSourceID="SqlDataSource3"
                                                                                                        DataTextField="subtype" DataValueField="subtype" AutoPostBack="True" OnSelectedIndexChanged="DropDownList4_SelectedIndexChanged">
                                                                                                    </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:521che_comConnectionString %>"
                                                                                                        SelectCommand="SELECT [subtype], [xilie] FROM [t_cars_subtype] WHERE (([xilie] = @xilie) AND ([chandi] = @chandi) AND ([pinpai] = @pinpai))">
                                                                                                        <SelectParameters>
                                                                                                            <asp:ControlParameter ControlID="DropDownList3" Name="xilie" PropertyName="SelectedValue"
                                                                                                                Type="String" />
                                                                                                            <asp:ControlParameter ControlID="DropDownList1" Name="chandi" PropertyName="SelectedValue"
                                                                                                                Type="String" />
                                                                                                            <asp:ControlParameter ControlID="DropDownList2" Name="pinpai" PropertyName="SelectedValue"
                                                                                                                Type="String" />
                                                                                                        </SelectParameters>
                                                                                                    </asp:SqlDataSource>
      protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    if (this.DropDownList1.SelectedValue == "请选择产地")
                    {
                        pic = "car/images/selectModel_blank.gif";                }
                    else
                    {
                        string sql = "select * from t_newcar where pinpai='" + this.DropDownList2.SelectedValue + "' and xilie='" + this.DropDownList3.SelectedValue + "' and chexing='" + this.DropDownList4.SelectedValue + "'";
                        DataSet ds = Maticsoft.DBUtility.DbHelperSQL.Query(sql);
                        DataTable dt = ds.Tables[0];
                      
                        pinpai = dt.Rows[0]["pinpai"].ToString();
                        chexing = dt.Rows[0]["chexing"].ToString();
                        leixing = dt.Rows[0]["newcar_type"].ToString();
                        changshang = dt.Rows[0]["newcar_factory"].ToString();
                        year = dt.Rows[0]["newcar_year"].ToString();
                        pic = "img/cars_image/";
                        pic += dt.Rows[0]["newcar_image"].ToString();
                        price = dt.Rows[0]["clear_price"].ToString();
                    }
                }
            }
      

  2.   

    who  can  help me?
      

  3.   

    你把你的DataSourceID去掉!!!用事件绑定,控件.DataSource= "你查出的数据"。不行吗??
    有是数据源绑定,又是后台DataSource赋值,我看的有点晕!!
      

  4.   

    在你的ddl_change事件的第一句代码处设置断断点。
    单步调试才是解决问题的王道。
      

  5.   

    在DropDownList的SelectedIndexChanged事件中还要绑定一次:
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList2.DataBind();
            DropDownList3.DataBind();
            DropDownList4.DataBind();
        }    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList3.DataBind();
            DropDownList4.DataBind();
        }    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList4.DataBind();
        }不太明白你在DropDownList4_SelectedIndexChanged的代码
    既然用SqlDataSource为什么还用传统的.
      

  6.   

    我也出现过这种情况,我当时是把dropdownlist的autopostback属性选上后就可以触发该事件了~~~