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

How to Access RadListBox Attributes in ClientItemTemplate

1 Answer 188 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Rosemary
Top achievements
Rank 1
Rosemary asked on 10 Sep 2013, 06:47 PM
Using the example from http://www.telerik.com/help/aspnet-ajax/listbox-client-templates.html, I was able to set up my ListBox using javascript to add items and attributes. When the item is added to my listbox, the text property is displayed but the other attributes are not.  When I view the rendered HTML, I can see that the attributes have been successfully added to my item. I would think that based on the ClientItemTemplate I have created, those values should show in the ListBox by the text, but they do not.

My end goal is to have the listbox display each attribute in table format.  Everything must be done clientside.  Any help is appreciated!

Rendered HTML:
< li class="rlbItem" id="selectMarketControl_RadListBox1_i0" Highlighted="False" StateCode="XY" City="Z" DataKey="123">
        <span class="rlbText">
                Text - Test Market

Javascript:
    //Get properties to add to the list box
    var nodeText = "Test Market";
    var dataKey = "123";
    var city = "Z";
    var stateCode = "XY";
    var highlighted = "False";
    //Create ListBox Item 
    var listbox = $find("<%= RadListBox1.ClientID %>");
    var item = new Telerik.Web.UI.RadListBoxItem();
    item.set_text(nodeText);
    item.set_value(dataKey);

//Set the list box item's custom attributes var attributes = item.get_attributes(); attributes.setAttribute("DataKey", dataKey); attributes.setAttribute("City", city); attributes.setAttribute("StateCode", stateCode); attributes.setAttribute("Highlighted", highlighted);
//Add item to the Listbox
listbox.trackChanges(); listbox.get_items().add(item); item.bindTemplate(); listbox.commitChanges();

ClientItemTemplate:

<
ClientItemTemplate> <table cellpadding="0" border="1" cellspacing="0" id="tblSelectedItems1"> <tr style="height: 18px;"> <td class="selectedMarketsGridColumnHospital"> #= Text # </td> <td class="selectedMarketsGridColumnCity"> #= Attributes.City # </td> <td class="selectedMarketsGridColumnState"> #= Attributes.StateCode # </td> <td style="text-align: center;" class="selectedMarketsGridColumnHighlighted"> <asp:CheckBox ID="Highlighted" runat="server" Checked=' #= Attributes.Highlighted #' ToolTip="Click to Highlight" Visible="true" /> </td> <td class="selectedMarketsGridColumnDelete"> <asp:ImageButton ID="btnRemove" AlternateText="Remove" Visible="true" Width="20px" runat="server" ImageUrl="../../Images/Buttons/btnGridRemove.gif" CommandName="Delete" CommandArgument='#= Attributes.DataKey #' ToolTip="Click to Remove" /> </td> </tr> </table> </ClientItemTemplate>

1 Answer, 1 is accepted

Sort by
0
Rosemary
Top achievements
Rank 1
answered on 11 Sep 2013, 01:21 PM
This has been resolved. I discovered that I was initiating an AJAX request after applying the ClientItemTemplate. Since the ClientItemTemplate is as it says, client side, the request was replacing my template with what I assume is a default template.
Tags
ListBox
Asked by
Rosemary
Top achievements
Rank 1
Answers by
Rosemary
Top achievements
Rank 1
Share this question
or