views:

51

answers:

1

I have a Dynamic Data linq to sql Website where I need to assign values on an specific cell in the insert or update pages. I have tried in the pageload of the Edit template

table.Columns[1].DefaultValue = User.Identity.Name;

but as is a metatable it is readonly.

Help...

A: 

To change the metadata, you have to add some attributes to the model class properties (you can find them in the DataContext generated classes if you use LinqToSql).

class User
{
  [DefaultValue("The default name")]
  string Name {get;set;}
}

But unfortunaly it will not be used by default by the dynamic data field templates, so you'll have to edit the templates to use the DefaultValue property, Exemple in the Page_Load of the TextEdit template:

if (!IsPostBack)
{
  if (Mode == DataBoundControlMode.Insert && Column.DefaultValue != null)
  {
      TextBox1.Text = Column.DefaultValue.ToString();
  }
}
Guillaume86