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

How to get List item's attribute in context menu's selection?

0 Answers 62 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Gangatharan
Top achievements
Rank 1
Gangatharan asked on 21 Mar 2018, 09:38 AM

I have two RadListBox. Data in first box is populated from database using RadListBoxItem and I have set an attribute for each item. In the second box, I've enabled custom context menu. After I adding the item from first box to second box, user can select some option using the context menu. On context menu selection, I need to get the Attribute I set before and update the attribute value according to the context menu selection so I can used it for later process.Currently, I unable to even the attributes I set previously using the context menu's javascript. Please guide how to read ListItem's attribute and update the attribute to a new value.

 

This is how I add the item to the first box with attribute.

this._sortingList = new List<Sorting>();
this._sortingList = DBConnection.getSortingList();
  
foreach (var s in this._sortingList)
 {
        RadListBoxItem item = new RadListBoxItem();
        item.Text = s.Description;
        item.Value = s.Id.ToString();
        item.Attributes["myorder"] = "0";
        this.RadListBox1.Items.Add(item);
}

 

This is custom context menu javascript.

function showContextMenu(sender, e) {
    var menu = $find("<%= cm1.ClientID %>");
    var rawEvent = e.get_domEvent().rawEvent; menu.show(rawEvent);
    e.get_item().select();
    $telerik.cancelRawEvent(rawEvent);
  
}
function onItemClicked(sender, e) {
    var listBox = $find("<%= RadListBox1.ClientID %>");
    var listItem = listBox.get_selectedItem();
    var menuItem = e.get_item();
    if (menuItem.get_text() == "Ascending"){
        alert(listItem.get_attributes().getAttribute("myorder"));
    }
    else if (menuItem.get_text() == "Descending") {
        alert(listItem.get_attributes().getAttribute("myorder"));
    }
}

No answers yet. Maybe you can help?

Tags
ListBox
Asked by
Gangatharan
Top achievements
Rank 1
Share this question
or