DropDownList不会在SelectedIndex Changed上回发

时间:2013-04-14 15:10:32

标签: c#

我正在尝试在更改所选项目时将DropDownList设置为AutoPostBack。为什么这不起作用,我有点疯狂。

有没有人有任何想法?请帮助

这是代码: -

     <asp:DropDownList ID="ddl_username" runat="server"
     AutoPostBack="True" 
     onselectedindexchanged="ddl_username_SelectedIndexChanged" 
     DataTextField="Shortname" DataValueField="ID">
     </asp:DropDownList>`

 protected void Page_Load(object sender, EventArgs e)
 {
    if (!IsPostBack)
    {
      Bind_Users();
    }
 }

 private DataSet Bind_Users()
{
DataSet ds;
ds = cs.BindUsers();
if (ds.Tables[0] != null)
{
    if (ds.Tables[0].Rows.Count > 0)
    {
        ddl_username.DataSource = ds.Tables[0];
        ddl_username.DataTextField = "Shortname";
        ddl_username.DataValueField = "ID";
        ddl_username.DataBind();
        ListItem li = new ListItem();
        li.Text = "Select";
        li.Value = "-1";
        ddl_username.Items.Insert(0, li);
        ddl_username.SelectedIndex = 0;
    }
    //ddl_username.SelectedIndex = 0;
    //ddl_username.Text = "-----Select-----";
}
return ds;
}

1 个答案:

答案 0 :(得分:0)

如果您想要致电Bind_Users(),请回复邮件:

if (!IsPostBack)
{
  Bind_Users();
}