Drop down list c#

问题内容:

I have dropdownlist like this

<asp:DropDownList ID="ddl1" runat="server" DataTextField="Val" DataValueField="ValID" AutoPostBack="true" OnSelectedIndexChanged="ddl1change"></asp:DropDownList>

<asp:DropDownList ID="ddl2" runat="server" DataTextField="Val" DataValueField="ValID" AutoPostBack="true" OnSelectedIndexChanged="ddl1change"></asp:DropDownList>

<asp:DropDownList ID="ddl3" runat="server" DataTextField="Val" DataValueField="ValID" AutoPostBack="true" OnSelectedIndexChanged="ddl1change"></asp:DropDownList>

This is the OnSelectedIndexChanged function in the cs page

 protected void ddl1change(object sender, EventArgs e)
{
    try
    {
        DropDownList ddltemp = sender as DropDownList;

        if (ddltemp.SelectedItem.Text != "---Select---")
        {
            selectedltrDropdownText = ddltemp.SelectedItem.Text;                    
            PassFileName(selectedltrDropdownText);                    
        }           
    }
    catch (Exception ex)
    {
        _logger.Error("Failed." + ex.Message + "; Stack Trace :" + ex.StackTrace);
    }

}

My Problem is: The functionality is that, There will be some file names in the dropdown.

When the file name is selected it should download the appropriate file in the given path.

First I am selecting a file in the First dropdown it downloads perfectly.

Secondly I select something in the dropdown 2 but the file which is selected dropdown 1 downloads again.

Note: If i Select any file in the second dropdown first, It downloads correctly. Any suggestions to achieve it with a single function?

问题评论:

    
I think you should be using multiple functions here for each drop down.
    
possibly you might be updating your first dropdown selected index or datasource on second dropdown selectedindexchange event
    
@Jamin:Why is it not possible to achieve it with a single function?
– Sam Daniel
9 hours ago
    
@Vicky S: No am not doing that. Both has different datasource
– Sam Daniel
9 hours ago
    
can you please put a break point to both of your dropdown selectedindexchange event where you can get clear view of the issue

原文地址:

https://stackoverflow.com/questions/47747540/drop-down-list-c-sharp

添加评论