2013-05-09 72 views
0

不管我做什么,或者尝试下拉列表不只是工作,替代ASP.NET下拉列表

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

绑定在这里,

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

和这里的方法,该方法从来没有触发(我用的断点检查)

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

是否有任何替代??????????我需要填充使用下拉列表,

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 "); 
       } 
      } 

回答

3

没有为DropDownList没有定义Click事件。使用该事件为SelectedIndexChanged

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

相反OnSelectedIndexChanged您键入OnClick

声明下拉列表如下:

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

没有onclick事件礼物DROPDOWNLIST使用OnSelectedIndexChanged事件下拉列表。