当所选项目发生更改时,我试图将 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;
}