This is a migrated thread and some comments may be shown as answers.

SelectedIndexChanged of Dropdownlist in RadListView - data not changed

1 Answer 228 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
sharon
Top achievements
Rank 1
sharon asked on 16 May 2016, 06:07 AM

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

1 Answer, 1 is accepted

Sort by
0
sharon
Top achievements
Rank 1
answered on 16 May 2016, 06:22 AM

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

Tags
DropDownList
Asked by
sharon
Top achievements
Rank 1
Answers by
sharon
Top achievements
Rank 1
Share this question
or