0
你好我试图删除列表中的一个值,当它在一个下拉列表中选择,但第一次我调用Button1_Click1它总是删除第一个索引(在此情况下)我不知道什么是对asp.net下拉列表第一次返回第一个值
List<String> Alph = new List<String>();
protected void Page_Load(object sender, EventArgs e)
{
if ((List<String>)Session["Alpha"] != null)
{
Alph = (List<String>)Session["Alpha"];
}
else
{
fillAlpha();
}
}
public void fillAlpha()
{
Alph = new List<String>() { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
Alph.Sort();
DropDownList1.DataSource = Alph;
DropDownList1.DataBind();
}
protected void Button1_Click1(object sender, EventArgs e)
{
Label1.Text = DropDownList1.Text;
Alph.RemoveAt(DropDownList1.SelectedIndex);
DropDownList1.DataSource = Alph;
DropDownList1.DataBind();
Session["Alpha"] = Alph;
}
你缺少'如果' – Vivekh 2014-10-02 18:44:26