私の解決策は、Paulの要件とは少し異なります。
DynamicData \ PageTemplates \ Insert.aspx.csファイルで、共有フィールドを持つテーブルの新しいレコードのデフォルトを表示するように編集しました。ユーザーはまだ挿入時に何か他のものを入れることができます。
public partial class Insert : System.Web.UI.Page
{
protected MetaTable table;
protected void Page_Init(object sender, EventArgs e)
{
table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
var values = table.GetColumnValuesFromRoute(Context);
// set default values for meta data of new records across all tables
// unknown values will be skipped
values.Add("creationDate", DateTime.Now);
values.Add("modificationDate", DateTime.Now);
values.Add("modificationUser", HttpContext.Current.User.Identity.Name.Substring(
HttpContext.Current.User.Identity.Name.IndexOf("\\") + 1));
FormView1.SetMetaTable(table, values);
DetailsDataSource.EntityTypeFilter = table.EntityType.Name;
}
[...]
}
既存の値でレコードを編集するために、いくつかのDynamicData\FieldTemplatesファイルに変更を加えました。
public partial class Text_EditField : System.Web.DynamicData.FieldTemplateUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
// ...
// show current user as value for the modification user upon editing records
if (Column.Name == "modificationUser")
{
FieldValue = Page.User.Identity.Name.Substring(Page.User.Identity.Name.IndexOf("\\") + 1);
}
}
[...]
}
編集用のページに更新された値が表示されますが、更新後は変更が保持されません。[ページの編集]テンプレートに追加の変更が必要です。
protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
// make sure a meta data update is always triggered by setting a different old value
// required for the edit components
if (e.OldValues.Contains("modificationUser"))
{
e.OldValues["modificationUser"] = string.Empty;
e.OldValues["modificationDate"] = DateTime.MinValue;
}
}