.net中的列表框处理 [英] list box handling in asp .net

查看:74
本文介绍了.net中的列表框处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想将所有选定的列表框项目从一个列表框复制到客户端的另一个列表框.该怎么做?
问候.
shefeek

Hi all,

I want to copy all selected listbox items from one list box to another in client side.how can do this?
regards,.
shefeek

推荐答案

大家好,
我有答案.
HI all,
I have got the answer.
<%@ 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>
        <script>
    function MoveItem(ctrlSource, ctrlTarget) {
        var Source = document.getElementById(ctrlSource);
        var Target = document.getElementById(ctrlTarget);
        if ((Source != null) && (Target != null)) {
            while ( Source.options.selectedIndex >= 0 ) {
                var newOption = new Option(); // Create a new instance of ListItem
                newOption.text = Source.options[Source.options.selectedIndex].text;
                newOption.value = Source.options[Source.options.selectedIndex].value;

                Target.options[Target.length] = newOption; //Append the item in Target
                Source.remove(Source.options.selectedIndex);  //Remove the item from Source
            }
        }
    }
</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>


<table height="150" width="300">
    <tr>
        <td>
            <asp:ListBox id="ListBox1" runat="server" Height="111px" SelectionMode="Multiple">
                <asp:ListItem Value="1">One</asp:ListItem>
                <asp:ListItem Value="2">Two</asp:ListItem>
                <asp:ListItem Value="3">Three</asp:ListItem>
            </asp:ListBox>
        </td>
        <td>
            <p>
                <input onclick="Javascript:MoveItem('ListBox1', 'ListBox2');" type="button" value="->" />
            </p>
            <p>
                <input onclick="Javascript:MoveItem('ListBox2', 'ListBox1');" type="button" value="<-" />
            </p>

        </td>
        <td>
            <asp:ListBox id="ListBox2" runat="server" Height="111px" SelectionMode="Multiple">
                <asp:ListItem Value="8">Eight</asp:ListItem>
                <asp:ListItem Value="9">Nine</asp:ListItem>
                <asp:ListItem Value="10">Ten</asp:ListItem>
            </asp:ListBox>
        </td>
    </tr>
</table>


    </div>
    </form>
</body>
</html>


这篇关于.net中的列表框处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆