Mathematics
Mathematics

Reputation: 7628

Alternative to ASP.NET drop down list

Regardless of what I do or try drop down list isn't just working,

<asp:DropDownList ID="drop1" runat="server" AutoPostBack="true" enabledviewstate="true" OnClick="Drop1_SelectedIndexChanged" />

bind it here,

  protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDropDownList();
            }
            //drop1.SelectedIndexChanged += new EventHandler(Drop1_SelectedIndexChanged);
        }

and here's method, which never triggers (I use break point to check)

protected void Drop1_SelectedIndexChanged(object sender, EventArgs e)
{
    //checkboxlist1.Items.Add("hahahha");
}

Is there any alternative ?????????? I need to populate the Drop down list using,

 using (SqlDataSource ds = new SqlDataSource(ConnectionString(), SelectCommand()))
            {
                System.Data.DataView dv = (System.Data.DataView)ds.Select(DataSourceSelectArguments.Empty);
                if (dv.Count > 0)
                {
                    drop1.DataSource = ds;
                    drop1.DataTextField = "UserName";
                    drop1.DataBind();
                    drop1.Items.Insert(0, "Please select a Username ");
                }
            }

Upvotes: 0

Views: 1873

Answers (3)

Rakesh_HBK
Rakesh_HBK

Reputation: 181

No Onclick event present for Dropdownlist use OnSelectedIndexChanged event for Dropdownlist.

Upvotes: 1

Nitin S
Nitin S

Reputation: 7601

Instead OnSelectedIndexChanged you typed OnClick

declare dropdownlist as follows:

<asp:DropDownList ID="drop1" runat="server" AutoPostBack="true" enabledviewstate="true" OnSelectedIndexChanged="Drop1_SelectedIndexChanged" />

Upvotes: 1

Andrei
Andrei

Reputation: 56716

There is no Click event defined for DropDownList. The event to use is SelectedIndexChanged:

<asp:DropDownList ID="drop1" runat="server"
                  AutoPostBack="true"
                  EnabledViewState="true"
                  OnSelectedIndexChanged="Drop1_SelectedIndexChanged" />

Upvotes: 3

Related Questions