This is a migrated thread and some comments may be shown as answers.

Detecting which transfer button was clicked

3 Answers 200 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 12 Oct 2010, 09:17 PM
How can I detect (server side) which transfer button was clicked during a RadListBox "Transferring" event?

I have a RadTreeView in the ItemTemplate of a RadListBox and another RadListBox on the destination side.  I have DragAndDrop and Transfer working both ways except TransferAll from the RadTreeView side does not work.  To Transfer from that side I had to loop through the SelectedNodes from the RadTreeView and I intend to simply set all the Nodes to Selected but how can I detect that the "TransferAll" button was clicked?

Thanks,
Dan

3 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 15 Oct 2010, 01:29 PM
Hello Dan,

I'm not sure I understand your scenario, could you please send us some sample code? Thanks in advance

Best regards,
Yana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Dan
Top achievements
Rank 1
answered on 15 Oct 2010, 04:18 PM
<asp:Panel runat="server" id="pnlUsers" CssClass="fieldPanelPadBottomClearedLeft" style="margin-bottom: 10px;">
  
    <div style="float: left; width: 325px; vertical-align: middle; margin-left:10px;">
        <asp:Label runat="server" id="Label3"
                    AssociatedControlId="radUserList"
                    Text="Users:" />
  
        <telerik:RadListBox 
            runat="server" ID="radUserList"
            Width="100%" Height="200px"
            SelectionMode="Single"
            AllowTransfer="true"
            TransferToID="radAssignedUserList"
            AutoPostBackOnTransfer="true"
            AllowReorder="false"
            EnableDragAndDrop="true" CssClass="RadListBox1"
            OnTransferring="radUserList_Transferring"
            DataTextField="Name"
            DataValueField="Id">
            <ItemTemplate>
                <telerik:RadTreeView 
                    ID="UsersTreeView" 
                    Runat="server"
                    EnableViewState="true"
                    EnableDragAndDrop="true"
                    MultipleSelect="true"
                    OnNodeDrop="UsersTreeView_NodeDrop"
                    OnClientNodeDropping="onTreeViewDropping"
                    OnClientMouseOver="onTreeViewMouseOver"
                    OnClientMouseOut="onTreeViewMouseOut" 
                    OnClientNodeDragStart="onTreeViewDragStart"
                    OnClientNodeDragging="onTreeViewDragging"
                    EnableDragAndDropBetweenNodes="false"
                    Width="100%"
                    Height="190px">
                    <DataBindings>
                        <telerik:RadTreeNodeBinding 
                            TextField="Name" 
                            ValueField="Id" 
                            ToolTipField="Name" 
                            HoveredCssClass="TreeViewDraggableNode" />
                    </DataBindings>
                </telerik:RadTreeView>
            </ItemTemplate>
            <Items>
                <telerik:RadListBoxItem Value="" Text="" AllowDrag="false" />
            </Items>
        </telerik:RadListBox>
    </div>
  
    <div style="float: left; width: 450px;">
        <asp:Label ID="Label2" runat="server"
                    AssociatedControlId="radAssignedUserList"
                    Text="Users assigned to this Distribution List:" />
  
        <telerik:RadListBox 
            runat="server" ID="radAssignedUserList"
            Width="100%" Height="200px"
            SelectionMode="Multiple"
            AllowReorder="false"
            EnableDragAndDrop="true"
            DataValueField="Id"
            OnClientDropping="onListBoxDropping" 
            OnClientDragStart="onListBoxDragStart" 
            OnClientMouseOver="onListBoxMouseOver"
            OnClientMouseOut="onListBoxMouseOut" 
            OnClientDragging="onListBoxDragging">
            <HeaderTemplate>
                <asp:Label runat="server" Width="200" Text="Name" />
                <asp:Label runat="server" Width="125" Text="Group" />
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Label 
                    runat="server" ID="lblUserName"  
                    Width="200" 
                    Text='<%# DataBinder.Eval(Container.DataItem, "Name")%>' />
                <asp:Label 
                    runat="server" ID="lblUserGroup" 
                    Width="200" 
                    Text='<%# DataBinder.Eval(Container.DataItem, "GroupName")%>' />
            </ItemTemplate>
        </telerik:RadListBox>
    </div>
  
    <div style="clear: both; padding: 10px; text-align: center;">
        <em>Note:  To move a User or Group, drag to the other window or highlight it and click arrow.<br />(Ctrl + Left-Click to select multiple)</em>
    </div>
  
</asp:Panel>
Above is the aspx code for the two ListBoxes and the embedded TreeView.  Below is the Transferring method I am using.
protected void radUserList_Transferring(object sender, RadListBoxTransferringEventArgs e)
{
    try
    {
        int distributionListId = 0;
        if (!int.TryParse(txtDistributionListId.Text, out distributionListId))
            return;
        if (distributionListId <= 0)
            return;
        DistributionList selectedDistributionList = new DistributionList(AppSession, distributionListId);
        if (e.SourceListBox == radUserList)
        {
            // If the TransferAll button was clicked, need to set all UserTreeView nodes  
            //   to Selected.  So far we haven't found how to determine which button was 
            //   clicked so am using combination of no selected nodes in UsersTreeView and 
            //   no selected items in radUserList to select all.  ISSUE:  When something   
            //   is selected clicking TransferAll, the TransferAll will act just like the  
            //   Transfer button and only transfer the selected item(s).
            if (UsersTreeView.SelectedNodes.Count.Equals(0) && radUserList.SelectedItems.Count.Equals(0))
            {
                foreach (RadTreeNode n in UsersTreeView.Nodes)
                {
                    n.Selected = true;
                }
            }
            RadTreeView rtv = (RadTreeView)e.Items[0].FindControl("UsersTreeView");
            foreach (RadTreeNode node in rtv.SelectedNodes)
            {
                if (node.Level != 0)
                {
                    int userId = int.Parse(node.Value);
                    selectedDistributionList.IncludeUser(userId);
                }
                else
                {
                    foreach (RadTreeNode subNode in node.Nodes)
                    {
                        int userId = int.Parse(subNode.Value);
                        selectedDistributionList.IncludeUser(userId);
                    }
                }
            }
            radUserList.Items[0].Selected = false;
        }
        else
        {
            foreach (RadListBoxItem item in e.Items)
            {
                int userId = int.Parse(item.Value);
                selectedDistributionList.RemoveUser(userId);
            }
        }
        e.Cancel = true;
        // bind the parts section
        BindUsers(selectedDistributionList);
    }
    catch (QueCentreException qex)
    {
        lblDistributionListMessage.Text = "Error: " + qex.Message;
        if (qex.InnerException != null)
        {
            lblDistributionListMessage.Text += "<br />Details: " + qex.InnerException.Message;
        }
        lblDistributionListMessage.Visible = true;
        this.Complete(false);
    }
}

Thanks for your help,
Dan
0
Accepted
Yana
Telerik team
answered on 21 Oct 2010, 01:22 PM
Hello Dan,

Please subscribe to OnClientTransferring event of the first listbox and add the following javascript handler:

<script type="text/javascript">
    function clientTransfering(sender, args) {
        var target = args.get_domEvent().target.parentNode;
        while (target.nodeName != "A")
            target = target.parentNode;
        sender.trackChanges();
        if (target.className.indexOf("rlbTransferFrom") > -1)
            sender.get_items().getItem(0).get_attributes().setAttribute("clickedButton", "transferFrom");
        else if (target.className.indexOf("rlbTransferAllFrom") > -1)
            sender.get_items().getItem(0).get_attributes().setAttribute("clickedButton", "transferAllFrom");
        sender.commitChanges();
   }
 </script>

then you can get the custom attribute in OnTransferring event like this:

String transferButton = (sender as RadListBox).Items[0].Attributes["clickedButton"].ToString();

Hope this helps.

Regards,
Yana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ListBox
Asked by
Dan
Top achievements
Rank 1
Answers by
Yana
Telerik team
Dan
Top achievements
Rank 1
Share this question
or