get_clientDataKeyValue() is always empty

2 posts, 0 answers
  1. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 25 May 2012 Link to this post

    I have a ListView defined like this ...
    <telerik:RadListView runat="server"
                         ClientDataKeyNames="ContactId, Surname, Forename, Organisation, Email">
            <div id="listview"
                 class="RadListView RadListView_#= owner.Skin #">
                <asp:Panel runat="server"
            <ClientEvents OnCommand="radListView1_OnCommand"/>
                    <div class="item">
                            <strong>#= String.format("{0}, {1}", Surname, Forename) #</strong>
                        <div>#= Organisation #</div>
                        <div>#= Email #</div>
                    <div class="item selected">
                            <strong>#= String.format("{0}, {1}", Surname, Forename) #</strong>
                        <div>Home: #= HomePhone #</div>
                        <div>Mobile: #= Mobile #</div>

    When an item in the ListView is clicked, the following code runs...
    var clientDataValues = listView.get_clientDataKeyValue()[index];

    Where index is the item index of the item clicked.

    My problem is that clientDataValues is always empty. I know that the value of index is correct 'cos the items selected state toggles correctly. Even if I hard-code an index it's empty.

    Am I supposed to cast a different spell if I'm client-side binding?


  2. Tsvetina
    Tsvetina avatar
    2481 posts

    Posted 30 May 2012 Link to this post

    Hello Stuart,

    I am just posting the suggested approach in this scenario, along with the explanation in case anyone is interested. You could later update the thread if you come up with a more interesting solution :)

    The ClientDataKeyNames and the respective values collections have been implemented when there was no client-side binding for RadListView, so you can have access to values that are available only on the server.
    However, with client binding, you get the whole binding context client-side and these values are accessible, so the key values collection is not populated.

    Here is one implementation that would provide you with the same result. The service is a public one, so you can test the whole mark-up locally:
    <script type="text/javascript">
        function itemSelected(index, keyValue) {
    <asp:ScriptManager runat="server" ID="ScriptManager1">
    <telerik:RadListView runat="server" ID="RadListView1" AllowMultiItemSelection="false"
            <DataBinding ItemPlaceHolderID="items">
                            <div id="listview" class="RadListView RadListView_#= owner.Skin #">
                                <div id="items" style="border-top: 1px solid grey; overflow-y: scroll"  />
                <DataService Location=""
                    ResponseType="JSONP" HttpMethod="Get" FilterParameterType="OData" SortParameterType="OData" />
                            <div class="item" onclick="itemSelected('#=index#', '#=ProductID#')">
                                <span style="line-height:50px">#=ProductName#</span>

    All the best,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top