做了一个网站,两个Listbox 数据互转
listbox1的数据是直接加载的
往listbox2中添加时选中无效。。。
代码如下
protected void Button3_Click(object sender, EventArgs e)
{
int count = ListBox1.Items.Count;
int index = 0;
for (int i = 0; i < count; i++)
{
ListItem newitem = ListBox1.Items[index];
if (ListBox1.Items[index].Selected == true)
{
ListBox1.Items.Remove(newitem);
ListBox2.Items.Add(newitem);
}
else { index++; }
}
}
ListBox1.Items[index].Selected == true 判断似乎不起作用。。。
数据绑定的部分是:
.......................................省略部分
SqlDataAdapter da = new SqlDataAdapter(mycom);
DataTable newtable = new DataTable();
da.Fill(newtable);
ListBox1.DataSource = newtable;
ListBox1.DataBind();
mycon.Close();
希望高手指教