Rajeshkumar Kandhasamy
Rajeshkumar Kandhasamy

Reputation: 6461

Drop Down List Event failed to execute

In my drop-down list, the SelectedIndexChanged event is not firing. I set AutoPostBack="True" but it's still not firing. Setting EnableViewState to True or False makes no difference either.

Here's my code:

<asp:DropDownList ID="ddlSheerName" runat="server" Width="250" AutoPostBack="True"
 OnSelectedIndexChanged="ddlSheerName_SelectedIndexChanged"></asp:DropDownList>

protected void Page_Load(object sender, EventArgs e)
{
    loggedInUserId = Convert.ToString(Session["LoggedInUserId"]);
    if (loggedInUserId == "")
    {
        Response.Redirect("Login.aspx");
    }
    if (Page.IsPostBack == false)
    {
        BindCompanyDropDown();

    }
}

protected void ddlSheerName_SelectedIndexChanged(object sender, EventArgs e)
{
    Bindcolumnname();
}

public void BindCompanyDropDown()
{
    try
    {
        objData = new DBFile();
        DataSet dsCompanies = objData.GetCompaniesList(loggedInUserId);
        if (dsCompanies != null)
        {
            if (dsCompanies.Tables[0].Rows.Count > 0)
            {
                ddlselectcompany.DataSource = dsCompanies;
                ddlselectcompany.DataTextField = "CompanyName";
                ddlselectcompany.DataValueField = "CompanyID";
                ddlselectcompany.DataBind();
            }
        }
    }
    catch (Exception ex)
    {
        lblMsg.Text = ex.Message;
    }
}

Upvotes: 0

Views: 855

Answers (3)

Peter
Peter

Reputation: 174

Is your event registred in the designer?
Select the dropdown and check the events assigned to it.

Upvotes: 0

Jack Marchetti
Jack Marchetti

Reputation: 15754

Viewstate must be enabled for this particular code to work and Javascript must be enabled for AutoPostBack to function.

Upvotes: 1

Steve Wellens
Steve Wellens

Reputation: 20640

The dropdown itself doesn't cause the event to fire.

You must actually change the selected item for the event to fire.

Upvotes: 1

Related Questions