Mark Hollas
Mark Hollas

Reputation: 1137

One DropDownList does not fire SelectedIndexChanged But Other Does

I am having a issue that I just can figure why it is happening

the situation is that I have two dropdownlists, both set up the same way

<asp:DropDownList ID="DocumentLink" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DocumentLink_Changed">
                </asp:DropDownList>
                <asp:DropDownList ID="PageLink" runat="server" AutoPostBack="true" OnSelectedIndexChanged="PageLink_Changed">
                </asp:DropDownList>

Their events look like this

protected void DocumentLink_Changed(object sender, EventArgs e)
    {
        DropDownList DocumentLink = sender as DropDownList;
        LinkParam = DocumentLink.SelectedValue.ToString();
        DescriptionParam = DocumentLink.SelectedItem.Text;
    }
    protected void PageLink_Changed(object sender, EventArgs e)
    {
        DropDownList PageLink = sender as DropDownList;
        LinkParam = PageLink.SelectedValue.ToString();
        DescriptionParam = PageLink.SelectedItem.Text;
    }

In the case of the DropDown called "PageLink" the event handler fires. However for the "DocumentLink" the event handler does not. In debug I see that page load is fired but the event drops off after the page load and never enters DocumentLink_Changed

As an point of interest if I use a telerik radComboBox in place of the DropDownList using the same set-up it does work.

<telerik:RadComboBox ID="DocumentLink" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DocumentLink_Changed">
                </telerik:RadComboBox>

with the event handler like this

protected void DocumentLink_Changed(object sender, RadComboBoxSelectedIndexChangedEventArgs e)

unfortunately I need to use Dropdownlists for my project.

What could be causing this?

UPDATE

I have taken the working dropdownlist and used the LINQ binding for the dropdownlist that did not work. The result was that the PageLink dropdownlist began to behave just like the 'DocumentLink' dropdownlist. This makes me believe that the issue might be in the binding method but they the two are very similar and I do see results in the dropdownlist

this is my binding

if (selectedValue == 3)
            {
                DropDownList select = lvLinks.InsertItem.FindControl("PageLink") as DropDownList;
                List<IPW_Links_get_document_listResult> getList = (from i in lqContext.IPW_Links_get_document_list(0, "my stuff") select i).ToList();
                select.DataSource = getList;
                select.DataTextField = "DocumentName";
                select.DataValueField = "FolderPath";
                select.DataBind();

            }
            if (selectedValue == 2)
            {
                DropDownList select = lvLinks.InsertItem.FindControl("PageLink") as DropDownList;
                List<IPW_Links_get_available_pagesResult> getList = (from i in lqContext.IPW_Links_get_available_pages(PortalId) select i).ToList();
                select.DataSource = getList;
                select.DataTextField = "TabName";
                select.DataValueField = "TabPath";
                select.DataBind();
            }   

Upvotes: 0

Views: 1210

Answers (1)

Vimal Raj
Vimal Raj

Reputation: 1038

do check if you have any statements in the PageLoad event that alters the dropdownlists. If you have a databinding statement or a selection reset statement in the page load event , then make sure it is under the if not ispostback conditional snippet.

Upvotes: 0

Related Questions