ListBox1控件单击选中后自动添加至另一个ListBox2中。
2007-12-26 16:44
337 查看
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindLsb();
}
}
#region 绑定listbox
protected void BindLsb()
{
SqlConnection conn = CDB.Getconn("constr","1");
conn.Open();
CDB.BindListBox(ListBox1, "select * from caes_memberinfo_column_dictionary", "columnname_inchinese", "columnid", conn);
}
#endregion
#region 按钮
//全部增加
protected void Button1_Click(object sender, EventArgs e)
{
ListBox2.Items.Clear();
for (int i=0;i<ListBox1.Items.Count;i++)
{
ListItem Listitem = new ListItem(ListBox1.Items[i].Text, ListBox1.Items[i].Value);
ListBox2.Items.Add(Listitem);
}
}
////增加一项
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string state = "0";
if (ListBox2.Items.Count > 0)
{
for (int j = 0; j < ListBox2.Items.Count; j++)
{
if (ListBox2.Items[j].Value == ListBox1.SelectedItem.Value)
{
state = "1";
ListBox1.SelectedItem.Selected = false;
Response.Write("<script>alert('已经有该选项了,请重新选择!')</script>");
break;
}
}
if (state == "0")
{
ListBox2.Items.Add(ListBox1.SelectedItem);
ListBox2.Items.FindByValue(ListBox1.SelectedItem.Value).Selected = false;
}
}
else
{
ListBox2.Items.Add(ListBox1.SelectedItem);
ListBox2.Items.FindByValue(ListBox1.SelectedItem.Value).Selected = false;
}
}
////删除一项
protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < ListBox2.Items.Count; i++)
{
if (ListBox2.Items[i].Selected == true)
{
ListBox2.Items.Remove(ListBox2.SelectedItem);
}
}
}
//删除全部
protected void Button4_Click(object sender, EventArgs e)
{
for (int i = 0; i < ListBox2.Items.Count; i++)
{
ListBox2.Items.Clear();
}
}
#endregion
{
if (!IsPostBack)
{
BindLsb();
}
}
#region 绑定listbox
protected void BindLsb()
{
SqlConnection conn = CDB.Getconn("constr","1");
conn.Open();
CDB.BindListBox(ListBox1, "select * from caes_memberinfo_column_dictionary", "columnname_inchinese", "columnid", conn);
}
#endregion
#region 按钮
//全部增加
protected void Button1_Click(object sender, EventArgs e)
{
ListBox2.Items.Clear();
for (int i=0;i<ListBox1.Items.Count;i++)
{
ListItem Listitem = new ListItem(ListBox1.Items[i].Text, ListBox1.Items[i].Value);
ListBox2.Items.Add(Listitem);
}
}
////增加一项
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string state = "0";
if (ListBox2.Items.Count > 0)
{
for (int j = 0; j < ListBox2.Items.Count; j++)
{
if (ListBox2.Items[j].Value == ListBox1.SelectedItem.Value)
{
state = "1";
ListBox1.SelectedItem.Selected = false;
Response.Write("<script>alert('已经有该选项了,请重新选择!')</script>");
break;
}
}
if (state == "0")
{
ListBox2.Items.Add(ListBox1.SelectedItem);
ListBox2.Items.FindByValue(ListBox1.SelectedItem.Value).Selected = false;
}
}
else
{
ListBox2.Items.Add(ListBox1.SelectedItem);
ListBox2.Items.FindByValue(ListBox1.SelectedItem.Value).Selected = false;
}
}
////删除一项
protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < ListBox2.Items.Count; i++)
{
if (ListBox2.Items[i].Selected == true)
{
ListBox2.Items.Remove(ListBox2.SelectedItem);
}
}
}
//删除全部
protected void Button4_Click(object sender, EventArgs e)
{
for (int i = 0; i < ListBox2.Items.Count; i++)
{
ListBox2.Items.Clear();
}
}
#endregion
相关文章推荐
- 我在用dotnet做一个项目的过程中,遇到了一个ListBox的问题:通过在一个ListBox中双击,把选中的项添加到另一个ListBox中
- Flex中如何给DataGrid控件的项目添加一个可编辑TextArea/TextInput,单击控件内的项目时,自动进入编辑状态
- Flex中如何给DataGrid控件的项目添加一个可编辑TextArea/TextInput,单击控件内的项目时,自动进入编辑状态
- 在工具栏(ToolBar)上添加ComboBox控件,为何每次在下拉列表中选择时,都会自动的选中工具栏上的一个按钮?
- js 实现 将一个 ListBox 的项添加到另一个ListBox
- AndroidStudio添加为activity绑定控件代码自动生成插件
- VB6 Add-Ins 自动添加控件前缀
- 单击行,自动选中当前行中的单选框按钮
- 为DataList控件添加自动编号的功能
- jQuery jForm ajax 单击选中文件直接自动上载 无需提交按钮
- jQuery EasyUI动态添加控件或者ajax加载页面后不能自动渲染问题的解决方法
- Gwt ListBox选中自动触发事件
- checkedListBox设置单击选中
- xml中搭建布局,当添加控件的时候自动生成的<Button android:layout_width="" android:layout_height="" />变成一行了
- Flex4.0 Spark List控件添加新Item自动滚动到底部
- xlistview网络请求数据以及添加headerview_自动轮播viewpager控件
- 自动添加控件,一次提交多条记录。
- 在VS2005和2008的对话框里,添加了一个MSCOMM通信控件,怎么mscomm.h和mscomm.cpp没有自动出现?
- 控件之DataGrid----实现自动添加新行和数据交换
- GridView后台自动添加行、列,行列不固定,并且再列里面添加服务器控件,然后取值