RadDropDownList OnSelectedIndexChanged doesn't hit event method

3 posts, 0 answers
  1. Jeremy
    Jeremy avatar
    29 posts
    Member since:
    Apr 2014

    Posted 04 Apr Link to this post

    I added a RadDropDownList to my user control and added a OnSelectedIndexChanged but when I run the project and change the dropdown index, it doesn't hit the OnSelectedIndexChanged method.

    <telerik:RadDropDownList ID="RadDropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadDropDownList1_SelectedIndexChanged">
        <Items>
            <telerik:DropDownListItem Text="-- ALL --" Value="0" />
            <telerik:DropDownListItem Text="Test 1" Value="1"  />
            <telerik:DropDownListItem Text="Test 2" Value="2" />
        </Items>
    </telerik:RadDropDownList>
    protected void RadDropDownList1_SelectedIndexChanged(object sender, Telerik.Web.UI.DropDownListEventArgs e)
    {
        int x = -1;
        x = e.Index;
    }

    I put a breakpoint on the first line of the SelectedIndexChanged method and it never gets in there.

  2. Jeremy
    Jeremy avatar
    29 posts
    Member since:
    Apr 2014

    Posted 04 Apr Link to this post

    Clarification:  I realized the event isn't firing because the user control this DropDownList is in is dynamically created in code.  When I move the DropDownList out of that user control and into the one that's creating it, it works.  The problem is, I need the DropDownList to work in the dynamically created user control.

    I create a RadTab and RadPageView for each party in my record set.  Then once the tab and page view are created, it inserts a user control with the party's information on it.  The DropDownList filter's the party's information.

    ucHistoryTabs.ascx

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucHistoryTabs.ascx.cs" Inherits="ucHistoryTabs" %>
     
    <div style="width: 100%; padding:0px 0px 10px 0px;">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Label runat="server" ID="ErrorMessageLabel" Text="" Visible="false" style="font-size: x-large; color:red" />
                <telerik:RadTabStrip ID="PartyTabStrip" runat="server" MultiPageID="HistorysPages" Skin="" Width="100%" ScrollChildren="true" ScrollButtonsPosition="Right">
                    <Tabs></Tabs>
                </telerik:RadTabStrip>
                <telerik:RadMultiPage ID="HistorysPages" runat="server" Width="95%"></telerik:RadMultiPage>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>

    ucHistoryTabs.ascx.cs

    public void BuildTabs(List<PartyInfo> allPartyInfos)
    {
        try
        {
            List<int> partyIDs = new List<int>();
            partyIDs = allPartyInfos.Select(i => i.PartyID).Distinct().ToList();
     
            foreach (int partyID in partyIDs)
            {
                List<PartyInfo> infoByParty = new List<PartyInfo>();
                infoByParty.Clear();
                infoByParty = allPartyInfos.Where(i => i.PartyID == partyID).ToList();
     
                string partyName = string.Empty;
                if (infoByParty.Count > 0)
                    partyName = infoByParty[0].PartyName;
     
                //first check to see if the tab exists before creating it.
                if (PartyTabStrip.Tabs.Where(t => t.Text == partyName).Count() < 1)
                {
                    #region Tab
                    Telerik.Web.UI.RadTab tab = new Telerik.Web.UI.RadTab();
                    tab.CssClass = "radtab-alltabs";
                    tab.SelectedCssClass = "radtab-selectedtab";
                    tab.Text = partyName;
                    tab.Value = "p_" + partyID.ToString();
                    tab.PageViewID = "p_" + partyID.ToString();
                    PartyTabStrip.Tabs.Add(tab);
                    #endregion
     
                    #region Page
                    Telerik.Web.UI.RadPageView page = new Telerik.Web.UI.RadPageView();
                    page.ID = "p_" + partyID.ToString();
     
                    if (infoByParty.Count > 0)
                    {
                        ucHistoryDisplay ucWHD = (ucHistoryDisplay)LoadControl("~/ucHistoryDisplay.ascx");
                        ucWHD.FillData(infoByParty);
                        ucWHD.ID = "d_" + partyID.ToString();
                        page.Controls.Add(ucWHD);
                    }
                    else
                    {
                        System.Web.UI.WebControls.Label lbl = new System.Web.UI.WebControls.Label();
                        lbl.ID = "d_" + partyID.ToString();
                        lbl.Text = "No records found";
                        page.Controls.Add(lbl);
                    }
                    #endregion
                    HistorysPages.PageViews.Add(page);
                }
            }
            if (PartyTabStrip.Tabs.Count > 0)
                PartyTabStrip.Tabs[0].Selected = true;
            if (HistorysPages.PageViews.Count > 0)
                HistorysPages.PageViews[0].Selected = true;
        }
        catch (Exception ex) { ThrowError(ex, "BuildTabs"); }
    }

    ucHistoryDisplay.ascx

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucHistoryDisplay.ascx.cs" Inherits="uctHistoryDisplay" %>
     
    <div style="padding-left:20px;">
        <asp:Table runat="server" ID="FilterControls" Width="100%">
            <asp:TableRow>
                <asp:TableCell>Status</asp:TableCell>
                <asp:TableCell>
                    <telerik:RadDropDownList runat="server" ID="StatusDropDown" OnSelectedIndexChanged="StatusDropDown_SelectedIndexChanged" AutoPostBack="true" AppendDataBoundItems="true">
                        <Items>
                            <telerik:DropDownListItem Text="-- ALL --" Selected="true" />
                        </Items>
                    </telerik:RadDropDownList>
                </asp:TableCell>
                <asp:TableCell>Type</asp:TableCell>
                <asp:TableCell>
                    <telerik:RadDropDownList runat="server" ID="TypeDropDown" OnSelectedIndexChanged="TypeDropDown_SelectedIndexChanged" AutoPostBack="true" AppendDataBoundItems="true">
                        <Items>
                            <telerik:DropDownListItem Text="-- ALL --" Selected="true" />
                        </Items>
                    </telerik:RadDropDownList>
                </asp:TableCell>
                <asp:TableCell>Number of Records</asp:TableCell>
                <asp:TableCell><asp:label runat="server" ID="Count" /></asp:TableCell>
            </asp:TableRow>
        </asp:Table>
    </div>
     
    <telerik:RadGrid ID="HistoryRadGV" runat="server" AutoGenerateColumns="false" ShowHeader="false"
                    Skin="" style="padding-left: 0px; width: 100%" ItemStyle-BackColor="#FFFFFF"
                    AlternatingItemStyle-BackColor="#F5F5F5" OnItemDataBound="HistoryRadGV_ItemDataBound">
    </telerik:RadGrid>

    ucHistoryDisplay.ascx.cs

            public void FillData(List<PartyInfo> selectedInfo)
            {
                try
                {
                    List<string> myStatuses = new List<string>();
                    myStatuses = selectedInfo.Select(w => w.Status).Distinct().OrderBy(q => q).ToList();
                    StatusDropDown.DataSource = myStatuses;
                    StatusDropDown.DataBind();
     
                    List<string> myTypes = new List<string>();
                    myTypes = selectedInfo.Select(w => w.Type).Distinct().OrderBy(q => q).ToList();
                    TypeDropDown.DataSource = myTypes;
                    TypeDropDown.DataBind();
     
                    Count.Text = selectedInfo.Count.ToString();
     
                    HistoryRadGV.DataSource = selectedInfo;
                    HistoryRadGV.DataBind();
                }
                catch (Exception ex)
                {
                    ThrowError(ex, "FillData");
                }
            }
     
            protected void StatusDropDown_SelectedIndexChanged(object sender, Telerik.Web.UI.DropDownListEventArgs e)
            {
    //do stuff
    }
     
            protected void WarrantTypeDropDown_SelectedIndexChanged(object sender, Telerik.Web.UI.DropDownListEventArgs e)
            {
    //do stuff
    }

    Presumably, because I create this user control dynamically, the SelectedIndexChanged events never fire when I change the DropDownList.

     

    Thoughts?

     

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 06 Apr Link to this post

    Hello Jeremy,

    I replied to the identical thread you started in the Ticketing System. If you have any further questions on this subject you can ask them there. 

    Regards,
    Ivan Danchev
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top