日期:2014-05-18  浏览次数:20494 次

如何把listbox中的值循环取出来?
listbox中有很多个值
我在把这些值取出来添加到表中
 比如listbox中有张三.李四,王五我就要把他们全部取出来然后一条一条添加到数据库怎么加?


------解决方案--------------------
C# code

ArrayList objArrayList = new ArrayList();
foreach (object a in listBox1.Items) {
   objArrayList.Add(a);
}

------解决方案--------------------
写了一个,你试一下
HTML code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListBox ID="ListBox1" runat="server" Height="279px" Width="294px">
            <asp:ListItem>张三</asp:ListItem>
            <asp:ListItem>李四</asp:ListItem>
            <asp:ListItem>王老五</asp:ListItem>
        </asp:ListBox>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="取值" Width="179px" /></div>
    </form>
</body>
</html>

------解决方案--------------------
这其实是简单的一个循环遍历问题,如1楼和2楼所述,还有就是看你要取它的text和value了。。。