两个listbox,点击按钮将左边选中的插入到右边,点击另一个按钮又把右边的删除,然后点击第三个按钮取出第二个listbox里所有的值。protected void Button1_Click(object sender, EventArgs e)//添加到新listbox
{
for (int k = 0; k < ListBox1.Items.Count; k++)
{
if ((ListBox1.Items[k].Selected) && (ListBox4.Items.FindByValue(ListBox1.Items[k].Value) == null))
{
ListItem item = ListBox1.Items[k];
ListBox4.Items.Add(item);
}
}
}
以上代码没有作用啊,请大大帮忙!!
{
for (int k = 0; k < ListBox1.Items.Count; k++)
{
if ((ListBox1.Items[k].Selected) && (ListBox4.Items.FindByValue(ListBox1.Items[k].Value) == null))
{
ListItem item = ListBox1.Items[k];
ListBox4.Items.Add(item);
}
}
}
以上代码没有作用啊,请大大帮忙!!
解决方案 »
- .net 在wap开发中后台跳转(重定向)的问题
- 用linq怎么做这个群发功能
- 用asp.net可以让图片不被下载吗?
- 如何写一个Page基类,在里面判断session,让其他页面继承?
- 怎样在网页中绑定textbox这个控件,答对给分
- 简单的数据库连接问题,请指教
- 为什么这个网站,第一次访问的时候能显示,再刷新的时候就不行了?地址:http://www.royiconsulting.com
- SqlCacheDependency是针对单表的缓存,多表的缓存如何处理?
- 重装IIS后如何恢复支持.NET?
- 关于datagrid中模板列的binding问题
- 关于页面嵌套问题
- jquery文本框的blur事件中无法实现事件末尾重新得到焦点??
==========
ListBox4.Items.FindByValue(ListBox1.SelectedValue)
{
int total = this.ListBox4.Items.Count;
int index=0;
for (int k = 0; k < total; k++)
{
ListItem item = this.ListBox4.Items[index];
if (this.ListBox4.Items[index].Selected)
{
this.ListBox4.Items.Remove(item);
index--;//listbox删除一行后,后面的一行将自动移上去
}
index++;
}
}如何修改啊?
JS实现,几个重要的点
移动
var v = lst1.options[lstindex].value;
var t = lst1.options[lstindex].text;
lst2.options[lst2.options.length] = new Option(t,v,true,true);删除
var lstindex=lst2.selectedIndex;
lst2.options[lstindex].parentNode.removeChild(lst2.options[lstindex]);取值
var length = lib.options.length;
for (var i = 0; i < length; i++) {
strText = strText + lib.options[i].innerText + ",";
strValue = strValue + lib.options[i].value + ",";
}
{
for (int i = 0; i < lst1.SelectedItems.Count; i++)
{
}
}
string listBox1 = this.ListBox1.SelectedItem.Text;
this.ListBox2.Items.Add(listBox1);
this.ListBox1.Items.Remove(listBox1); <asp:ListBox ID="lst_left" runat="server" SelectionMode="Multiple" Height="203px"
Width="130px"></asp:ListBox>
<asp:ListBox ID="lst_center" runat="server" SelectionMode="Multiple" Height="203px" Width="130px"></asp:ListBox>
<input type="button" id="btn_leftToCenter" value="右移" onclick="MoveOption(document.getElementById('lst_left'),document.getElementById('lst_center'))" />
<input type="button" id="btn_centerToLeft" value="左移" onclick="MoveOption(document.getElementById('lst_center'),document.getElementById('lst_left'))" />function MoveOption(fromSel,toSel)
{
var fromOp=fromSel.options;
var toOp=toSel.options;
var selectedFlag=false;
for(var i=0;i<fromOp.length;i++)
{
if(fromOp[i].selected)
{
selectedFlag=true;
var selectedOp=document.createElement("option");
selectedOp.text=fromOp[i].text;
selectedOp.value=fromOp[i].value;
toSelLength=toOp.length;
toSel.options.add(selectedOp,toSelLength);
fromSel.options.remove(i);
i--;
}
}
if(!selectedFlag)
{
alert("请选择一项!");
return;
}
}
protected void Button1_Click(object sender, EventArgs e) //右移事件 左边的向右边的移
{
int str = ListBoxDad.Items.Count;
if (str > 0)
{
for (int i = 0; i < str; i++)
{
//Response.Write((bool)ListBoxSon.Items[i].Selected);
if (ListBoxDad.SelectedIndex != -1)
{
string s_t = ListBoxDad.SelectedItem.Text;
string s_v = ListBoxDad.SelectedItem.Value; ListBoxSon.Items.Add(new ListItem(s_t, s_v));
ListBoxDad.Items.Remove(ListBoxDad.SelectedItem); }
} }
else
{
UserClass userclass = new UserClass();
userclass.Alert("alert('都没东西,叫我移什么啊!')");
}
}
左边的ListBox内部移动
protected void Button3_Click(object sender, EventArgs e) //上移位事件
{ int index = -1;
int str = ListBoxDad.Items.Count;
UserClass userclass = new UserClass();
if (str > 0)
{
if (ListBoxDad.SelectedIndex != -1)
{
if (ListBoxDad.SelectedIndex != 0)
{
ListItem listitem = new ListItem(ListBoxDad.SelectedItem.Text, ListBoxDad.SelectedItem.Value);
ListBoxDad.Items[ListBoxDad.SelectedIndex].Text = ListBoxDad.Items[ListBoxDad.SelectedIndex + index].Text;
ListBoxDad.Items[ListBoxDad.SelectedIndex].Value = ListBoxDad.Items[ListBoxDad.SelectedIndex + index].Value;
ListBoxDad.Items[ListBoxDad.SelectedIndex + index].Text = listitem.Text;
ListBoxDad.Items[ListBoxDad.SelectedIndex + index].Value = listitem.Value;
}
else
{
userclass.Alert("alert('已经是最上面的,请选择别的!')");
}
}
} }
protected void Button4_Click(object sender, EventArgs e) //下移位事件
{
int index = 1; //定义下移变量
int str = ListBoxDad.Items.Count;
UserClass userclass = new UserClass();
if (str > 0)
{
if (ListBoxDad.SelectedIndex != -1)
{
if (ListBoxDad.SelectedIndex < (str - 1))
{
ListItem listitem = new ListItem(ListBoxDad.SelectedItem.Text, ListBoxDad.SelectedItem.Value);
ListBoxDad.Items[ListBoxDad.SelectedIndex].Text = ListBoxDad.Items[ListBoxDad.SelectedIndex + index].Text;
ListBoxDad.Items[ListBoxDad.SelectedIndex].Value = ListBoxDad.Items[ListBoxDad.SelectedIndex + index].Value;
ListBoxDad.Items[ListBoxDad.SelectedIndex + index].Text = listitem.Text;
ListBoxDad.Items[ListBoxDad.SelectedIndex + index].Value = listitem.Value;
}
else
{
userclass.Alert("alert('已经是最下面的,请选择别的!')");
}
}
}
}
<asp:ListBox ID="ListBox1" runat="server" Height="182px" SelectionMode="Multiple"
Width="113px">
<asp:ListItem>北京</asp:ListItem>
<asp:ListItem>江苏</asp:ListItem>
<asp:ListItem>浙江</asp:ListItem>
</asp:ListBox>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="添加" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="删除" />
<asp:Button ID="Button3" runat="server" Text="取值" OnClick="Button3_Click" />
<asp:ListBox ID="ListBox2" runat="server" Height="179px" SelectionMode="Multiple"
Width="121px"></asp:ListBox>
protected void Button2_Click(object sender, EventArgs e)//移动按钮事件
{
ListBox2.Items.Add(ListBox1.SelectedItem);//将listbox1中的选中项移到listbox2中
}
protected void Button1_Click1(object sender, EventArgs e)//删除按钮事件
{
ListBox2.Items.RemoveAt(ListBox2.SelectedIndex);//删除listbox2中的选中项
}
protected void Button3_Click(object sender, EventArgs e)//取值
{
string[] arr = new string[ListBox2.Items.Count];//ListBox2.Items.Count获得项数
for (int i = 0; i < ListBox2.Items.Count; i++)//循环取出每项的值
{
arr[i] = ListBox2.Items[i].Text;
}
foreach (string li in arr)//循环输出每项的值
Response.Write(li);
}
实现方法如上,具体的细节方面楼主自己添加