【问题标题】:Alternative to ASP.NET drop down list替代 ASP.NET 下拉列表
【发布时间】:2013-05-03 20:48:41
【问题描述】:

无论我做什么或尝试下拉列表都不起作用,

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

【问题讨论】:

    标签: c# javascript sharepoint webforms controls


    【解决方案1】:

    没有为DropDownList 定义Click 事件。使用的事件是SelectedIndexChanged:

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

    【讨论】:

      【解决方案2】:

      你输入的是OnSelectedIndexChangedOnClick

      如下声明下拉列表:

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

      【讨论】:

        【解决方案3】:

        Dropdownlist 不存在 Onclick 事件,使用 Dropdownlist 的 OnSelectedIndexChanged 事件。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-10-29
          • 1970-01-01
          • 2014-11-25
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多