2011-01-28 8 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

+0

@enjoyprogramming : originalList 줄에 대한 주석을 제거하면 코드가 완벽하게 작동해야합니다. 뭐가 문제 야? – JPReddy

+0

주석 처리 된 행을 제거한 후 해당 행이 작동하지 않습니다. –

답변

0

jquery에서 변경 한 내용을 숨김 필드 값으로 저장합니다. f.e. 쉼표로 구분 된 값 목록으로, 변경된 값을 서버 측에서 분할하여 목록 상자에 추가합니다. 그렇지 않으면 변경 사항은 포스트 백 이후에 유지되지 않습니다.

Items not added to ListBox after using jQuery .appendTo

관련 문제