2012-04-20 60 views
0

好吧,我只想知道我在想甚麼可能。我試過研究,但沒能找到任何東西。我有兩個可以在它們之間傳輸數據的RadLsitBox。我想知道是否可以添加撤消按鈕,可以撤消我最後一次轉移。Telerik RadListBox,通過代碼轉移項目

FYI客戶想要一個撤消按鈕。我不認爲這是可能的,只有通過代碼才能通過代碼沒有按下按鈕,但如果有人有我想聽到的方式。

<telerik:RadListBox ID="rlbStations" runat="server" AllowTransfer="True" TransferToID="rlbAllowedStations" 
          Height="200px" Skin="Web20" SelectionMode="Multiple" Sort="Ascending" DataKeyField="station_id" 
          AutoPostBackOnTransfer="true" Width="250px" OnTransferred="rlbStations_Transferred"> 
          <ButtonSettings ShowDelete="False" ShowReorder="False" /> 
         </telerik:RadListBox> 

         <telerik:RadListBox ID="rlbAllowedStations" runat="server" Height="200px" Width="250px" 
          Skin="Web20"> 
         </telerik:RadListBox> 

編輯:添加JavaScript

var UndoList = new Array(); 
    function onClientTransferring(sender, e) { 
     var items = e.get_items(); 
     for (var i = 0; i < items.length; i++) { 
      var item = items[i]; 
      if (item.get_text() != "Select" || item.get_value() != "") { 
       UndoList.push(item); 
       UndoList.push(e.get_sourceListBox()); 
       UndoList.push(e.get_destinationListBox()); 
       sender.transferItem(item, e.get_sourceListBox(),e.get_destinationListBox()); 
      } 
     } 

    } 

    function undoChanges() { 
     if (UndoList[UndoList.length - 1]._clientStateFieldID == "rlbStations_ClientState") { 
     var listbox = $find('rlbStations'); 
     } 
    else if (UndoList[UndoList.length - 1]._clientStateFieldID == "rlbAllowedStations_ClientState") { 
     var listbox = $find('rlbAllowedStations'); 
     } 
     listbox.transferItem(UndoList[UndoList.length - 3], UndoList[UndoList.length - 2], UndoList[UndoList.length - 1]); 
    } 

回答

3

的答案是:有!您可以在不使用內置傳送按鈕的情況下傳送項目。下面是使用JavaScript作爲一個例子的代碼示例:

function onClientTransferring(sender, e) {debugger 
    //cancel the event 
    e.set_cancel(true); 
    //manually transfer the appropriate items 
    var items = e.get_items(); 
    for (var i = 0; i < items.length; i++) { 
     var item = items[i]; 
     if (item.get_text() != "Select" || item.get_value() != "") { 
      sender.transferItem(item, e.get_sourceListBox(), e.get_destinationListBox()); 
     } 
    } 
} 

而且RadListBox

<telerik:RadListBox ID="RadListBox1" 
    runat="server" 
    Skin="Vista" 
    AllowTransfer="true" 
    TransferToID="RadListBox2" 
    DataKeyField="ID" 
    OnClientTransferring="onClientTransferring" 
    DataTextField="Name" 
    DataValueField="ID"  
    DataSourceID="SqlDataSource1" >  
</telerik:RadListBox> 
<telerik:RadListBox ID="RadListBox2" runat="server" 
    Skin="Vista" 
    AllowTransfer="true"> 

http://www.telerik.com/help/aspnet-ajax/listbox-how-to-transfer-specific-items-with-transferall-button.html

+0

我只是嘗試此代碼,它使用內置的傳輸按鈕。 – cjohnson2136 2012-04-23 12:30:24

+0

我試着用它作爲另一個按鈕,但它甚至不會打這個代碼。即使您鏈接的文章也沒有提及不使用默認傳輸按鈕。 – cjohnson2136 2012-04-23 12:45:17

+0

您需要致電onClient從另一個按鈕或您選擇的任何按鈕轉移自己。這只是示例代碼,而不是最終解決方案。 – msigman 2012-04-23 12:48:40