我有 2 个按钮和一个ListBox
. 当我单击第一个按钮时,它应该从中删除选定的项目,ListBox
但它没有 -ListBox
保持不变。代码有什么问题?
static List<string> Blist = new List<string>();
public int x;
protected void Page_Load(object sender, EventArgs e)
{
Blist = (List<string>)Session["items"];
if (Blist != null)
{
ListBox1.Items.Clear();
for (int i = 0; i < Blist.Count; i++)
ListBox1.Items.Add(Blist[i]);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
x= ListBox1.SelectedIndex;
if (x >= 0)
{
ListBox1.Items.RemoveAt(x);
string m = Blist[x];
Blist.Remove(m);
Session["items"] = null;
Session["items"] = Blist;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Session["items"] = null;
}