Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Member
2 Points
1 Post
Sep 20, 2011 06:39 AM|LINK
I used your code and it didn't compiled and found that there are some changes made by Microsoft which are mentioned here:
http://www.asp.net/downloads/35-sp1/readme
FieldTemplateUserControlBase no longer exists. Change any instances of the Inherits attribute that reference the old class to reference the FieldTemplateUserControl class instead.
MetaMember changed to Column
DataItem has been changed to Row.
and so on.
Here is what it appears after the changes:
private string selectedValue = null; protected void Page_Load(object sender, EventArgs e) { selectedValue = EnumDDL.SelectedValue; string[] enumNames = Enum.GetNames(Column.ColumnType); Array.Sort(enumNames); EnumDDL.DataSource = enumNames; EnumDDL.DataBind(); } private string GetCurrentValue() { //DynamicMetaForeignKeyMember column = (DynamicMetaForeignKeyMember)MetaMember; object value = DataBinder.GetPropertyValue(Row, "Status"); if (value == null) return String.Empty; return value.ToString(); } protected override void OnDataBinding(EventArgs e) { base.OnDataBinding(e); if (Mode == DataBoundControlMode.Edit) { EnumDDL.SelectedValue = GetCurrentValue(); } } protected override void ExtractValues(IOrderedDictionary dictionary) { object val = null; if (string.IsNullOrEmpty(selectedValue)) { try { val = Enum.Parse(Column.ColumnType, EnumDDL.SelectedValue); } catch { } } else { val = selectedValue; } dictionary[Column.Name] = val; }
noman.aftab
Member
2 Points
1 Post
Re: Dynamic Data and Enum-bound fields
Sep 20, 2011 06:39 AM|LINK
I used your code and it didn't compiled and found that there are some changes made by Microsoft which are mentioned here:
http://www.asp.net/downloads/35-sp1/readme
FieldTemplateUserControlBase no longer exists. Change any instances of the Inherits attribute that reference the old class to reference the FieldTemplateUserControl class instead.
MetaMember changed to Column
DataItem has been changed to Row.
and so on.
Here is what it appears after the changes:
private string selectedValue = null; protected void Page_Load(object sender, EventArgs e) { selectedValue = EnumDDL.SelectedValue; string[] enumNames = Enum.GetNames(Column.ColumnType); Array.Sort(enumNames); EnumDDL.DataSource = enumNames; EnumDDL.DataBind(); } private string GetCurrentValue() { //DynamicMetaForeignKeyMember column = (DynamicMetaForeignKeyMember)MetaMember; object value = DataBinder.GetPropertyValue(Row, "Status"); if (value == null) return String.Empty; return value.ToString(); } protected override void OnDataBinding(EventArgs e) { base.OnDataBinding(e); if (Mode == DataBoundControlMode.Edit) { EnumDDL.SelectedValue = GetCurrentValue(); } } protected override void ExtractValues(IOrderedDictionary dictionary) { object val = null; if (string.IsNullOrEmpty(selectedValue)) { try { val = Enum.Parse(Column.ColumnType, EnumDDL.SelectedValue); } catch { } } else { val = selectedValue; } dictionary[Column.Name] = val; }