I have an ASP.NET WebForms page containing an ASPxGridView
and an ObjectDataSource
:
<dx:ASPxGridView ID="gvEmployees" runat="server"
AutoGenerateColumns="False" DataSourceID="objDsEmployees"
KeyFieldName="EmployeeId">
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0">
<EditButton Visible="True" />
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="EmployeeId" VisibleIndex="1" />
<dx:GridViewDataTextColumn FieldName="Name" VisibleIndex="2" />
<dx:GridViewDataTextColumn FieldName="Email" VisibleIndex="3" />
<dx:GridViewDataTextColumn FieldName="Telephone" VisibleIndex="5" />
</Columns>
</dx:ASPxGridView>
<asp:ObjectDataSource ID="objDsEmployees"
runat="server"
ConflictDetection="CompareAllValues"
DataObjectTypeName="MySite.Data.Models.Employee"
DeleteMethod="Delete"
OldValuesParameterFormatString="original{0}"
InsertMethod="Insert"
SelectMethod="GetAll"
TypeName="MySite.Services.EmployeeService"
UpdateMethod="Update" />
The Employee model contains the following properties:
public class Employee
{
public int EmployeeId { get; set; }
public string Name { get; set; }
public string Email { get;
public string Password { get; set; }
public string Telephone { get; set; }
}
The ObjectDataSource
calls the Update
method in the service layer:
public void Update(Employee employee, Employee originalEmployee)
{
_db.Employees.Attach(originalEmployee);
_db.Entry(originalEmployee).CurrentValues.SetValues(employee);
_db.SaveChanges();
}
When the Update
method is called, the parameters employee
and originalEmployee
only contain the properties used as columns in the ASPxGridView
and the other properties (Password
for example) are null.
Is there a way I can preserve these values somewhere? By the way, I use Entity Framework for data access and DevExpress for the GridView.