20分,关于ListBox的问题,急!!!

qb81195235 2007-06-26 08:52:48
我用了两个ListBox,左边的ListBox1通过双击将数据显示在ListBox2中。我要将ListBox2中显示的数据添加到数据库,ListBox2的数据都要添加。请问怎么将做,用的C#,帮帮忙!
...全文
275 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
nyzfl 2007-06-26
  • 打赏
  • 举报
回复
建议使用listBox
nyzfl 2007-06-26
  • 打赏
  • 举报
回复
lz逻辑不清楚,做法,应该是用户点“保存”按钮后,回发到服务器,你说是吧。
qb81195235 2007-06-26
  • 打赏
  • 举报
回复
xiaomatian(趴趴熊◎%#……※×) 能不能具体的写下代码呢。
ListBox1的值都不能赋给ListBox2,又怎么赋给隐藏的textbox。
bdbox@qq.com 2007-06-26
  • 打赏
  • 举报
回复
To xiaomatian(趴趴熊◎%#……※×) :你的方法是有效的,可是如果listbox中的值很多的话如何处理啊?

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
我的E-Mail:bdbox@163.com 请多指教!
xiaomatian 2007-06-26
  • 打赏
  • 举报
回复
用js写的话在后台取不到的ListBox的值的吧.我建议你在aspx页面上加一个隐藏域,比如一个隐藏的textbox之类的,你在给listbox2赋值的时候同时将这个值赋给这个隐藏域,然后在后台对这个隐藏域的值进行处理就可以了。

bdbox@qq.com 2007-06-26
  • 打赏
  • 举报
回复
如果按照你这样的说法的话,我在页面上放上一个textbox,在里面填写值,那么查看html代码仍无值哦``。那么提交何以成功?

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
我的E-Mail:bdbox@163.com 请多指教!
qb81195235 2007-06-26
  • 打赏
  • 举报
回复
在页面上看见listbox2里面有值了,但是你看页面的源代码里listbox2却没有值。全都在listbox1中。
bdbox@qq.com 2007-06-26
  • 打赏
  • 举报
回复
可是在客户端已经给listbox2赋了值了。

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
我的E-Mail:bdbox@163.com 请多指教!
qb81195235 2007-06-26
  • 打赏
  • 举报
回复
好象用JS双击添加的数据,没绑定到ListBox2中。
不知道怎么绑定给ListBox2。
bdbox@qq.com 2007-06-26
  • 打赏
  • 举报
回复
我也期待高手解答一下为什么提交时不能取到值?

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
我的E-Mail:bdbox@163.com 请多指教!
bdbox@qq.com 2007-06-26
  • 打赏
  • 举报
回复
代码:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="javascript">
function RemoveAllEvent()
{
RemoveAll(window.document.getElementById('select1'),window.document.getElementById('select2'));
}

function AddAllEvent()
{
RemoveAll(window.document.getElementById('select2'),window.document.getElementById('select1'));
}

function RemoveOneEvent()
{
RemoveOne(window.document.getElementById('select1'),window.document.getElementById('select2'));
}

function AddOneEvent()
{
RemoveOne(window.document.getElementById('select2'),window.document.getElementById('select1'));
}

function RemoveAll(selectSource,selectGoal)
{
var length = selectSource.length;

for(i = 0;i < length;i++)
{
var text = selectSource.options(i).text;
var value = selectSource.options(i).value;
var oOption = document.createElement("OPTION");
selectGoal.options.add(oOption);
oOption.innerText = text;
oOption.value = value;
}

for(i = 0;i < length;i++)
{
selectSource.options.remove(0);
}
}

function RemoveOne(selectSource,selectGoal)
{
var ar = new Array();//用于存储选择的项的索引
var length = selectSource.length;

for(i = 0;i < length;i++)
{
if (selectSource.options(i).selected)
{
var text = selectSource.options(i).text;
var value = selectSource.options(i).value;
var oOption = document.createElement("OPTION");
selectGoal.options.add(oOption);
oOption.innerText = text;
oOption.value = value;

ar[ar.length + 1] = selectSource.options(i);
}
}

for(i = 0;i < length;i++)
{
for(j = 0;j < ar.length;j++)
{
if (selectSource.options(i) == ar[j])
{
selectSource.options.remove(i);
}
}
}
}
</script>
</HEAD>
<body ms_positioning="GridLayout">
<form id="form1" runat="server">
<FONT face="宋体"></FONT> 
<SELECT style="WIDTH: 216px; HEIGHT: 264px" size="16" id="select1" multiple runat="server" ondblclick = "RemoveOneEvent()">
<OPTION value="0">你好0</OPTION>
<OPTION value="1">你好1</OPTION>
<OPTION value="2">你好2</OPTION>
<OPTION value="3">你好3</OPTION>
<OPTION value="4">你好4</OPTION>
</SELECT>         <INPUT id="btnAddAll" style="Z-INDEX: 103; LEFT: 264px; POSITION: absolute; TOP: 192px"
type="button" value=" << " onclick="AddAllEvent()">  <INPUT id="btnAddOne" style="Z-INDEX: 105; LEFT: 264px; POSITION: absolute; TOP: 144px"
type="button" value=" < " onclick="AddOneEvent()">   <INPUT id="btnRemoveOne" style="Z-INDEX: 104; LEFT: 264px; POSITION: absolute; TOP: 96px"
type="button" value=" > " onclick="RemoveOneEvent()"> <INPUT style="Z-INDEX: 102; LEFT: 264px; POSITION: absolute; TOP: 56px" type="button" value=" >> "
id="btnRemoveAll" onclick="RemoveAllEvent()">
<SELECT style="Z-INDEX: 101; LEFT: 336px; WIDTH: 224px; POSITION: absolute; TOP: 16px; HEIGHT: 262px"
size="16" id="select2" multiple runat="server" ondblclick = "AddOneEvent()">
</SELECT>
</form>
</body>
</HTML>


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
我的E-Mail:bdbox@163.com 请多指教!
qb81195235 2007-06-26
  • 打赏
  • 举报
回复
我是用JS将ListBox1的值通过双击显示在ListBox2中的。
function change1()
{
var addOption=document.createElement("option")
var index1
if(document.form1.ListBox1.length==0)return(false);
index1=document.form1.ListBox1.selectedIndex
if(index1<0)return(false);

addOption.text=document.form1.ListBox1.options(index1).text
addOption.value=document.form1.ListBox1.value
document.form1.ListBox2.add(addOption);
document.form1.ListBox1.remove (index1)
我要怎么将ListBox1双击的数据绑定给ListBox2呢?我是菜鸟不懂啊!!
bdbox@qq.com 2007-06-26
  • 打赏
  • 举报
回复
我试过用js写的,好像不成功。如果你愿意我可以贴出来给你看一下。

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
我的E-Mail:bdbox@163.com 请多指教!
qb81195235 2007-06-26
  • 打赏
  • 举报
回复
就是用JS写的,是不是这个有问题啊!!
ListBox2里面不能得到数据!
Dleno 2007-06-26
  • 打赏
  • 举报
回复
string StrText1,StrValue1,StrText2,StrValue2;

for (int i = 0; i < ListBox1.Items.Count; i++)
{
StrText1 = ListBox1.Items[i].Text;
StrValue1 = ListBox1.Items[i].Value;
Label6.Text += StrText1 + "的值是" + StrValue1 + "<br/>";
}

for (int z = 0; z < ListBox2.Items.Count; z++)
{
StrText2 = ListBox2.Items[z].Text;
StrValue2 = ListBox2.Items[z].Value;
Label6.Text += StrText2 + "的值是" + StrValue2 + "<br/>";
}


如果还是不行,就看看你的Page_Load事件里怎么写的,是否把绑定数据的代码写到了!Page.IsPostBack里
konic 2007-06-26
  • 打赏
  • 举报
回复
ondbclick的时候的代码,你该不会是用JS写的吧?
foreach(ListItem item in ListBox2.Items)
{
Label6.Text += item.Text + "的值是" + item.Value + "<br/>";
}
bdbox@qq.com 2007-06-26
  • 打赏
  • 举报
回复

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (ListItem item in this.ListBox1.Items)
{
this.TextBox1.Text += item.Text + ":" + item.Value + ";";
}
}
}
没有什么意思啊,我试了能够成功显示出来。

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
我的E-Mail:bdbox@163.com 请多指教!
qb81195235 2007-06-26
  • 打赏
  • 举报
回复
怎么没人回哦,自己顶下!我用这个
string StrText;
string StrValue;
for (int i = 0; i < FunName.Items.Count; i++)
{
StrText = FunName.Items[i].Text;
StrValue = FunName.Items[i].Value;
Label6.Text += StrText + "的值是" + StrValue + "<br>";
}
但是只能读取出ListBox1中的值,ListBox2中的值怎么也读不出来!!
wen01071081 2007-06-26
  • 打赏
  • 举报
回复
可以全用js来做,保存用ajax

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧