I use Dyanamic Data Field Template to make websites is just started using such things I had learned all about it, but has forgotten how to customize it... Is there anyone who know how to customize Dynamic Data Field Template...???
I use Dyanamic Data Field Template to make websites is just started using such things I had learned all about it, but has forgotten how to customize it... Is there anyone who know how to customize Dynamic Data Field Template...???
Dynamic Data field templates are ASP.NET user controls that map data controls to data types in a data model. Field templates derive from FieldTemplateUserControl, the class that enables access to data fields, data columns, and metadata in data models. Dynamic Data projects provide some default field templates, but you can modify them or create custom field templates.
The following code is a partial class Entity type created for the Dynamic Data feild :
Code:partial void OnContextCreated() { this.SavingChanges += new System.EventHandler(OnSavingChanges); } public void OnSavingChanges(object sender, System.EventArgs e) { var stateManager = ((TransitScheduleEntities)sender).ObjectStateManager; var changedEntities = stateManager.GetObjectStateEntries(EntityState.Modified); foreach (ObjectStateEntry stateEntryEntity in changedEntities) { int modBy = stateEntryEntity.CurrentValues.GetOrdinal("ModifiedBy"); int modDate = stateEntryEntity.CurrentValues.GetOrdinal("DateModified"); if (modBy > 0) { stateEntryEntity.CurrentValues.SetValue(modBy, HttpContext.Current.User.Identity.Name); } if (modDate > 0) { stateEntryEntity.CurrentValues.SetValue(modDate, DateTime.Now); } } }
The following procedure shows how to add a background color to Text_Edit.ascx, one of the field templates provided in a Dynamic Data project by default. To customize a default field template :
- In Visual Studio 2008 or Visual Web Developer 2008 Express Edition open the ASP.NET Dynamic Data Web site.
- In the DynamicData/FieldTemplate folder, open the default field template you want to modifyand switch to Source view.
- Modify the code to customize the field template
For example, you can add the following code snippet to modify the Text_Edit.ascx field template
This code snippet adds a background color property to the markup and sets it to yellow.Code:<asp:TextBox ID="TextBox1" runat="server" BackColor="Yellow" Text='<%# FieldValueEditString %>'></asp:TextBox>
Bookmarks