Insert custom value into a cell in ASP.NET dynamic data

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

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

but like metatetable, it is read-only.

Reference...

+3
source share
2 answers

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

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

, , , , DefaultValue, Page_Load TextEdit:

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

, , .

:

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);
        }
}
+1

Source: https://habr.com/ru/post/1740522/


All Articles