Answered by:
Retrieving instanct of data object.

Question
-
User-1825738080 posted
Is there a way to retrieve the instance of the data object in the FieldTemplateUserControl?
I have an abstract data object that has some methods I would like to invoke in the dynamic templates.
Thursday, December 18, 2008 8:25 PM
Answers
-
User1641955678 posted
Yes, simply use the Row property for this. David- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, December 19, 2008 2:39 AM -
User1641955678 posted
Note that if you're using Entity Framework, Row will not directly be the entity, but a wrapper object (and hence 'Row as Category' would be null, but not Row itself). Please see this thread for information on how to unwrap it.
thanks,
David- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, December 22, 2008 3:54 PM
All replies
-
User1641955678 posted
Yes, simply use the Row property for this. David- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, December 19, 2008 2:39 AM -
User-1825738080 posted
The Row value is null
protected override void OnDataBinding(EventArgs e) { parent = FieldValue as Category; Category current = Row as Category; if(parent != null) { ParentTitle.Text = parent.Title; }else { ParentTitle.Text = FlexiCommerce.Context.Localization.GetResource("ROOT"); } base.OnDataBinding(e); }
current (Row) is always null. happens in edit and insert mode.Monday, December 22, 2008 3:44 PM -
User1641955678 posted
Note that if you're using Entity Framework, Row will not directly be the entity, but a wrapper object (and hence 'Row as Category' would be null, but not Row itself). Please see this thread for information on how to unwrap it.
thanks,
David- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, December 22, 2008 3:54 PM -
User-1825738080 posted
I checked the debugger. Row is null.
I am using a custom DataModelProvider giving my databound controls the IAutoFieldGenerator
I suspect that this would be the problem if your saying the Row works differently for different model providers.
Monday, December 22, 2008 5:30 PM -
User-1825738080 posted
public class DetailsView : System.Web.UI.WebControls.DetailsView
{
protected override void OnInit(EventArgs e)
{
this.DataKeyNames = new string[] {"ID"};
Type type = Type.GetType(ContextType);
this.RowsGenerator = Helpers.GetFieldGenerator(type);
base.OnInit(e);
}
public string ContextType
{
get { return this.ViewState["ContextType"] == null ? string.Empty : this.ViewState["ContextType"].ToString(); }
set { this.ViewState["ContextType"] = value; }
}
}I also am using a custom datasource that implements (but does little with) the IDynamicDataSource interface.
I am rather new to dynamic data.
Any ideas as to where to look for the problem?
Monday, December 22, 2008 5:36 PM -
User1641955678 posted
Note that all the Row property does is return Page.GetDataItem(), which is a basic ASP.NET databinding thing that's unrelated to Dynamic Data. Is Page.GetDataItem() null for you during data binding? If so, are you sure that your custom data source works correctly outside of Dynamic Data?
David
Monday, December 22, 2008 6:08 PM -
User-1825738080 posted
My datasource works correctly with normal databound controls.
My Page.GetDataItem() is null also.
Tuesday, December 23, 2008 1:32 AM -
User1641955678 posted
I don't see how standard databound controls can work if Page.GetDataItem() ins null, because it relies on it directly. e.g. the standard 'Eval' is implemented as:
protected object Eval(string expression) { return DataBinder.Eval(Page.GetDataItem(), expression); }
I'm probably missing some data about your scenario.
David
Tuesday, December 23, 2008 2:37 AM