views:

31

answers:

1

Hi,

I'm using SL4 and RIA services. I have a simple table with 3 fields (Name, UpDatedByUserId, UpDatedOn). In my metadata I use Data Annotation on the 2 latter fields so that they do not display. My DataGrid and the related DataForm show each record correctly and, as required, the DataForm only shows the Name field but of course I want to programmatically set values for the other 2 fields (UpDatedByUserId and UpDatedOn). Is there a way I can set those values in the ViewModel?

A: 

In your ViewModel you could setup your Name property like so:

private string _UpdatedByUserId;
private DateTime _UpdatedOn;
private string _Name;
public string Name 
{
   get { return _Name; }
   set
   {
      if(value != _Name)
      {
         _UpdatedByUserId = WebContext.Current.User.Name;
         _UpdatedOn = DateTime.Now;
         _Name = value;
      }
   }
}
Terry Nederveld
Terry even though all the fields are in the ViewModel I kept looking at the DataForm! Thanks again
Jim