Using DataItem in a UserControl

4 posts, 0 answers
  1. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2009

    Posted 19 Apr 2010 Link to this post

    Is there any documentation that explains how the DataItem property is structured?  What is passed to that property when using a user control to update/insert a new item?  How is it passed?

    I can retrieve all fields from the DataItem property EXCEPT the primary key.  I'm inserting/updating an Options row using a user control.  I can retrieve DataItem("Description"), DataItem("Category"), etc fields.  I just can't get DataItem("OptionsId") for some reason.  I get the IndexOutOfRangeException.

    Any suggestions?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Apr 2010 Link to this post

    Hello Matt,

    In order to fetch the primary key field values for grid items, you can use the DataKeyNames and DataKeyValues arrays of the GridTableView object. In aspx you can set the DataKeyNames property and value of that column becomes available in DataKeyValue. Check out the following code:

    <MasterTableView DataKeyNames="OptionsId"

    string OptionsId = DataItem.GetDataKeyValue("OptionsId").ToString(); 


  3. DevCraft R3 2016 release webinar banner
  4. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2009

    Posted 20 Apr 2010 Link to this post

    The issue with that is that the RadGrid is on the parent .aspx page.  And then I'm trying to retrieve OptionId in the edit/insert .ascx page.  Can I still retrive the DataKeyName from the .ascx?

    I tried it and got this error: Public member 'GetDataKeyValue' on type 'DataRecordInternal' not found.

    Any other ideas?  Thanks!

  5. Mira
    Mira avatar
    1124 posts

    Posted 23 Apr 2010 Link to this post

    Hello Matt,

    Please try using the following code to implement the desired functionality:
    '<%# DataBinder.Eval( Container, "DataItem.OptionsId") %>'

    For additional information, please take a look at the User Control Edit Form demo.

    All the best,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top