Getting DataKey from selected item

6 posts, 1 answers
  1. Ahrensberg
    Ahrensberg avatar
    73 posts
    Member since:
    Mar 2009

    Posted 21 Jan 2010 Link to this post

    Hi all,

    My MasterTable is defined by:

    <MasterTableView DataKeyNames="id">  
        <Columns> 
            <telerik:GridBoundColumn HeaderText="Street" DataField="Address.Street" />                                          
            <telerik:GridBoundColumn HeaderText="HouseNumber" DataField="Address.HouseNumber" /> 
            <telerik:GridBoundColumn HeaderText="ZipCode" DataField="Address.ZipCode.Code" /> 
            <telerik:GridBoundColumn HeaderText="City" DataField="Address.ZipCode.City" /> 
        </Columns> 
    </MasterTableView> 

    And I want to get the id of the selected item client side. I thought that this would do the trick:

    // Javascript  
    var selectedItem = $find("MyGridClientID").get_masterTableView().get_selectedItems()[0];  
    var selectedItemID = selectedItem.getDataKeyValue("id"); 

    But this 'selectedItemID' is following null. What do I do wrong? :o/
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Jan 2010 Link to this post

    Hello Ahrensberg,

    Try setting the ClientDataKeyNames property of the MasterTableView to the datafield of the column(id in your case).
    Check out the following document which shows an example:

    Thanks
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ahrensberg
    Ahrensberg avatar
    73 posts
    Member since:
    Mar 2009

    Posted 21 Jan 2010 Link to this post

    I tried to do as in the example:

    var firstDataItem = $find("MyGridClientID").get_masterTableView().get_dataItems()[0];  
    var keyValue = firstDataItem.getDataKeyValue("id"); 

    But keyValue is still null (firstDataItem is not)... :-S
  5. Ahrensberg
    Ahrensberg avatar
    73 posts
    Member since:
    Mar 2009

    Posted 21 Jan 2010 Link to this post

    DO'H! Should of course set 'ClientDataKeyNames' instead of 'DataKeyNames' - as you wrote! ;o)

    Thank you! :o)
  6. Martin de Ruiter
    Martin de Ruiter avatar
    99 posts
    Member since:
    Jun 2005

    Posted 08 Oct 2012 Link to this post

    What's the correct link to the Extracting key values client-side article?
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 Oct 2012 Link to this post

    Hi,

    Here is the link.
    Extracting Key Values Client-side

    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017