I have a dynamic data website which has a custom field template,
CustomFieldTemplate_Edit.ascx
that will be used inside
ListDetails.aspx
for some pages. I have set it up where I need it to using the UIHint attribute and I want to implement some custom functionality. For this I need a way to get the data of the current row that contains my CustomFieldTemplate. How can I do this ?
public partial class CustomFieldTemplate_Edit : System.Web.DynamicData.FieldTemplateUserControl
{
protected void Page_PreRender(object sender, EventArgs e)
{
//Need to get current row data, or at least the primary key here
}
}
I noticed that FieldTemplateUserControl has a Row property but I don't know how to use it. When I try to access it I get this error:
"Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."
I have found a solution here. The answer is the
Rowproperty of theFieldTemplateUserControl, but you have to access it in theOnDataBindingevent of the FieldTemplate.After you get the Row, you can get the entities from it using these extension methods(taken from the link above) and it all works like a charm.