Cancel event in OnItemClick method

4 posts, 0 answers
  1. Sandeep
    Sandeep avatar
    22 posts
    Member since:
    Apr 2013

    Posted 21 Aug 2014 Link to this post

    how to cancel event in RadTreeList_OnItemClick method.

    I am using below code

    function RadTreeList_OnItemClick(sender, eventArgs) {

                    var currentItem = eventArgs.get_item();
                    var item = eventArgs.get_item();                 
                    if (item.get_dataKeyValue('IsAlreadyAssigned') == 'True') {
                        if (eventArgs.get_item().get_selected())
                        {
                            <<<I NEED TO CANCEL EVENT HERE , SO IT DOES NOT DO ANYTHING JUST CANCEL IT>>>
                            selItem = '';                        
                        }
                        else
                        {
                            alert('2');                        
                            selItem = item.get_dataKeyValue('ObjectId')
                            eventArgs.get_item().set_selected(true);
                        }
                        
                    }
                    else {                     
                        selItem = '';                    
                                        
                    }

                }

    Please help
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Aug 2014 in reply to Sandeep Link to this post

    Hi Sandeep,

    It is very difficult to find out the exact requirement with the provided information. The ItemClick event of RadTreeList is fired when a data item is clicked in the RadTreeList and this event can not be cancelled. Please elaborate your requirement for further help.

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sandeep
    Sandeep avatar
    22 posts
    Member since:
    Apr 2013

    Posted 21 Aug 2014 in reply to Shinu Link to this post

    Hi Shinu,

    I am binding data to treelist with few columns, and one column is having value true or false.

    I am disabling the row if value is true.

    I want user should not be able to select or deselect that row when user click on it.

    but it should be selectable or deselectable if user clicks on parentitem row or parent item check box.

    Please let me know if I am still not clear.

    Regards,
    Sandeep
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Aug 2014 in reply to Sandeep Link to this post

    Hi Sandeep,

    Please try the below sample code snippet which works fine at my end.

    ASPX:
    <telerik:RadTreeList ID="RadTreeList1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="ID" ParentDataKeyNames="ParentID" AllowMultiItemSelection="True"AutoGenerateColumns="false" ResolvedRenderMode="Classic" OnItemDataBound="RadTreeList1_ItemDataBound">
        <Columns>
            <telerik:TreeListSelectColumn HeaderStyle-Width="38px">
            </telerik:TreeListSelectColumn>
            <telerik:TreeListBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
            </telerik:TreeListBoundColumn>
            <telerik:TreeListBoundColumn DataField="Text" UniqueName="Text" HeaderText="Text">
            </telerik:TreeListBoundColumn>
            <telerik:TreeListBoundColumn DataField="ParentID" UniqueName="ParentID" HeaderText="ParentID">
            </telerik:TreeListBoundColumn>
            <telerik:TreeListCheckBoxColumn DataField="Status" UniqueName="Status" HeaderText="Status">
            </telerik:TreeListCheckBoxColumn>
        </Columns>
        <ClientSettings>
            <ClientEvents OnItemSelected="OnClientNodeClicked" OnItemDeselected="OnClientNodeClicked" />
            <Selecting AllowItemSelection="true" />
        </ClientSettings>
    </telerik:RadTreeList>

    C#:
    protected void RadTreeList1_ItemDataBound(object sender, Telerik.Web.UI.TreeListItemDataBoundEventArgs e)
    {
        if (e.Item is TreeListDataItem)
        {
            TreeListDataItem item = (TreeListDataItem)e.Item;
            CheckBox status = item["Status"].Controls[0] as CheckBox;
            if (status.Checked)
            {
                item.Enabled = false;
            }
        }
    }

    JavaScript:
    function OnClientNodeClicked(sender, args) {
        var currNode = args.get_item();
        var childNodes = currNode.get_childItems();
        var nodeCount = currNode.get_childItems().length;
        var parentItem = currNode.get_parentItem();
        if (currNode.get_selected()) {
            CheckAllChildren(childNodes, nodeCount);
        }
        else {
            UnCheckAllChildren(currNode, childNodes, nodeCount);
        }
    }
    function UnCheckAllChildren(currNode, nodes, nodecount) {
        var i;
        for (i = 0; i < nodecount; i++) {
            nodes[i].set_selected(false);
        }
        currNode.set_selected(false);
    }
    function CheckAllChildren(nodes, nodecount) {
        var i;
        for (i = 0; i < nodecount; i++) {
            nodes[i].set_selected(true);
        }
    }

    Thanks,
    Shinu.
Back to Top