2011-01-28 40 views
0

每次當我點擊按鈕(btnadd)時,頁面都會後備。任何人都可以告訴我如何存儲listbox的選定值。在這裏我正在從一個列表框添加到另一個列表框。如何存儲列表框值的值?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ListBoxExample.aspx.cs" Inherits="ListBoxExample" 
    EnableEventValidation="false" %> 

<!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>Adding,removing elements from First Listbox to Second Listbox</title> 
    <style type="text/css"> 
     .lstbx1 
     { 
      font-family: Verdana; 
      font-size: medium; 
      font-style: normal; 
      background-color: Aqua; 
      height: auto; 
      width: auto; 
     } 
     .lstbx2 
     { 
      font-family: Verdana; 
      font-size: medium; 
      font-style: normal; 
      background-color: Lime; 
      height: auto; 
      width: auto; 
     } 
    </style> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js"></script> 
    <script type="text/javascript"> 
     jQuery(document).ready(function() { 
      $('#btnadd').click(function() { 
       // var originalList = $("#<%= this.lstbx1.ClientID %>"); 
       var items = $('option', originalList); 
       var targetList = $("#<%= this.lstbx2.ClientID %>"); 
       $("#lstbx1 option:selected").remove().appendTo("#lstbx2"); 
      }); 
     }); 


    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <table> 
      <tr> 
       <td> 
        <asp:ListBox ID="lstbx1" runat="server" CssClass="lstbx1" SelectionMode="Multiple"> 
         <asp:ListItem>John</asp:ListItem> 
         <asp:ListItem>Peter</asp:ListItem> 
         <asp:ListItem>Sam</asp:ListItem> 

        </asp:ListBox> 
       </td> 
       <td> 
        <asp:ListBox ID="lstbx2" runat="server" CssClass="lstbx2"></asp:ListBox> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <input type="button" id="btnadd" value="Add" /> 
       </td> 
       <td> 
        <asp:Button ID="btnremove" runat="server" Text="Remove" /> 
       </td> 
      </tr> 
     </table> 
    </div> 
    </form> 
</body> 
</html> 
+1

商店在哪裏?你有什麼嘗試?什麼沒有用? – Oded 2011-01-28 11:12:50

回答