SelectedIndexChanged of Dropdownlist in RadListView - data not changed

2 posts, 0 answers
  1. sharon
    sharon avatar
    26 posts
    Member since:
    Jul 2015

    Posted 16 May Link to this post

    Hi!

        I have 4-level hierarchical <asp:dropdownlist > items within <telerik:RadListView>, when I change the first level dropdownlist, the function SelectedIndexChanged was triggered, when the dataset returns nothing, I want to add an empty listitem to the dropdown, but, after the function has gone through completed, the listitem of 2nd tier still remain the same before selectedindexchanged, what has I missed? I have attached partial code below.

    Thanks in advanced.

    SH

    -- xxx.aspx
     <telerik:RadListView ID="RadLVFbData" DataKeyNames="FormId" runat="server" RenderMode="Lightweight"
                                ItemPlaceholderID="CSDetailContainer" OnNeedDataSource="RadLVFbData_NeedDataSource" OnItemCommand="RadLVFbData_ItemCommand"
                                OnItemDataBound="RadLVFbData_ItemDataBound" OnItemCreated="RadLVFbData_ItemCreated"
                                Skin="Silk">
       ...
       <table style="width:100%;border-collapse:separate" border="0">
                               <tr>
                                <td style="width: 25%">Type Category:</td>
                                <td style="width: 20%"><asp:DropDownList ID="ddlFBTypeL1" Width="100px" runat="server" OnSelectedIndexChanged="ddlFBTypeL1_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList></td>
                                <td style="width: 20%"><asp:DropDownList ID="ddlFBTypeL2" Width="120px" runat="server" OnSelectedIndexChanged="ddlFBTypeL2_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList></td>
                                <td style="width: 20%"><asp:DropDownList ID="ddlFBTypeL3" Width="120px" runat="server" OnSelectedIndexChanged="ddlFBTypeL3_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList></td>
                                <td><asp:DropDownList ID="ddlFBTypeL4" Width="120px" runat="server" OnSelectedIndexChanged="ddlFBTypeL4_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList></td>
                                </tr>
                            </table>                        
                                                       
     
     </telerik:RadListView>
    ---------------------------------------------------------------------------------------------------------------------------
    -- xxx.aspx.cs
     protected void ddlFBTypeL1_SelectedIndexChanged(object sender, EventArgs e)
            {
                try
                {
                    DataSet dsChild = new DataSet();
                    DataSet ds = new DataSet();
                    DropDownList elemDDLFBTypeL1 = sender as DropDownList;
                                    
                    //get next layer UI element for ddlFBTypeL1
                    DropDownList elemDDLFBTypeL2 = elemDDLFBTypeL1.NamingContainer.FindControl("ddlFBTypeL2") as DropDownList;
                   
                    string strFBTypeL1ID = "00001"; //first layer ID
                    string strFBTypeL1Val = elemDDLFBTypeL1.SelectedValue;
                    string strFBTypeL2ID = "";
                    //get data for 2nd layer
                    dsChild = objChoiceRelLogic.getChoiceRelByParentIdVal(strFBTypeL1ID, strFBTypeL1Val);
                    if (dsChild != null && dsChild.Tables[0].Rows.Count > 0)
                    {
                        ....
                    }
                    else
                    {
                        elemDDLFBTypeL2.DataSource = null;
                        elemDDLFBTypeL2.DataBind();
                        elemDDLFBTypeL2.Items.Insert(0, new ListItem("--------", ""));
                    }
                }
                catch(Exception ex)
                {
                    LogUtils.ErrorFormat("In ddlFBTypeL1_SelectedIndexChanged, exception: " + ex.Message);
                }
            }

  2. sharon
    sharon avatar
    26 posts
    Member since:
    Jul 2015

    Posted 16 May in reply to sharon Link to this post

    I think I got it, I place Items.Clear() for the first line of the conditon, then I got the result I want.

                        elemDDLFBTypeL2.Items.Clear();
                        elemDDLFBTypeL2.DataSource = null;
                        elemDDLFBTypeL2.DataBind();
                        elemDDLFBTypeL2.Items.Insert(0, new ListItem("--------", ""));

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top