This is a migrated thread and some comments may be shown as answers.
Using DataItem in a UserControl
3 Answers 72 Views
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 19 Apr 2010, 04:51 PM
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?

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 20 Apr 2010, 05:45 AM
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:

aspx:
<MasterTableView DataKeyNames="OptionsId"

C#:
string OptionsId = DataItem.GetDataKeyValue("OptionsId").ToString(); 

Regards,
Shinu.


0
Matt
Top achievements
Rank 1
answered on 20 Apr 2010, 04:38 PM
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!



0
Mira
Telerik team
answered on 23 Apr 2010, 09:01 AM
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,
Mira
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.
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Matt
Top achievements
Rank 1
Mira
Telerik team
Share this question
or