开发者

Insert Custom value on Cell in ASP.NET Dynamic Data

I have a Dynamic Data linq to sql Website whe开发者_StackOverflowre 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...


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();
  }
}


I know this is an old post, but this could help others in solving their problem.

You can use this:

public partial class BasicModelDataContext : DataContext
{
        partial void InsertEmployee(Employee instance)
        {
            instance.MyValue = "NEW VALUE";
            Employee.Insert(instance);
        }

        partial void UpdateEmployee(Employee instance)
        {
             instance.MyValue = "NEW Update VALUE";
             Employee.Update(instance);
        }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜