How to initialize a new object instance RRS feed

  • Question

  • I have a page that allows users to create new rows on the employee table.  I want to create a new employee object and set certain fields before I display it to the user i.e.

    Employee empl = new Employee {Active=true, HireDate=DateTime.Now.ToString()};

    I would like put this code in my datacontext class.  How do I do that?


    Thursday, February 12, 2009 4:06 AM


  •   This is more a UI issue that a datacontext one.

    Consider a blank form on the UI for entering the new data: the new Employee object has not been created and will not be until the user clicks the Submit (or Save or whatever) button.

    If you're using LINQDataSource it is only when submit is clicked that a new Employee instance is created.

    To solve your problem get the UI to pre-fill the fields with the values - or if you don't want the user to be able to edit them display as read-only fields.
    • Marked as answer by Sam2 Saturday, February 21, 2009 10:49 PM
    Thursday, February 12, 2009 1:15 PM