Hi,
I have a basic GridView control that is bound to a custom object data source as below:
<form id="form1" runat="server"><br />
<asp:GridView
ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White"
BorderColor="#999999" BorderStyle='Solid' BorderWidth='1px'
CellPadding='3' DataKeyNames='Id'
DataSourceID="EmployeesListDataSource" ForeColor="Black"
GridLines="Vertical">
<FooterStyle BackColor="#CCCCCC" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id"
InsertVisible="False" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
<asp:BoundField DataField="Surname" HeaderText="Surname"
SortExpression="Surname" />
<asp:BoundField DataField="JobTitle" HeaderText="Job Title"
SortExpression="JobTitle" />
</Columns>
<SelectedRowStyle BackColor="#000099" Font-Bold="True"
ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White"
/>
<AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>
</form>
<csla:CslaDataSource ID="EmployeesListDataSource" runat="server"
TypeName="classlib_cslatest.EmployeesList"
TypeAssemblyName="classlib_cslatest"
OnDeleteObject="EmployeesListDataSource_DeleteObject"
OnUpdateObject="EmployeesListDataSource_UpdateObject"
OnSelectObject="EmployeesListDataSource_SelectObject">
</csla:CslaDataSource>
As you can see, there are Id, Name, Surname and JobTitle fields,
and Id is the only key field (see DataKeyNames). The GridView is
successfully populated with rows and columns via the
EmployeesListDataSource_SelectObject() call. In other words, the column
names are correct, and all the rows of my Employee table is displayed
correctly. So my assumption is that data is bound correctly. Then when
I want to update the GridView, I do the following:
1) Click edit on the row that I want to modify.
2) Change the fields in a row that are enabled for modification.
3) Click update.
Then I expect to get updated fields in "UpdateObjectArgs e" argument to EmployeesListDataSource_UpdateObject() (See below).
But there are no keys defined in the UpdateObjectArgs argument for
the modified fields. I would expect to get e.Keys["Name"],
e.Keys["Surname"] and e.Keys["JobTitle"] to obtain new values, but
there are no such keys defined. The only defined dictionary key is "Id"
and that contains the original Id value, since it is defined in
DataKeyNames.
Could you think of a reason why Update wouldn't work? Could you
point me at the first point in the ASP.NET calls where the DataGrid
values are captured before being passed to UpdateObjectArgs? Maybe I
can debug it from there?
Thanks,
Bahadir
The function to update the database is as follows:
protected void EmployeesListDataSource_UpdateObject(
object sender, Csla.Web.UpdateObjectArgs e)
{
EmployeesList obj = GetEmployeesList();
try
{
// e.Keys["Id"] exists and keeps its original value.
Employee emp =
obj.getItem(new Guid(e.Keys["Id"].ToString()));
String total = string.Empty;
// Neither of the below keys exist:
MessageLabel.Text = "Name: " + e.Keys["Name"] +
"Surname: " +
e.Keys["Surname"] + "Jobtitle: " + e.Keys["JobTitle"];
//Csla.Data.DataMapper.Map(e.Values, emp);
MessageLabel.Text += "Total: " + total;
emp.Save();
e.RowsAffected = 1;
}
catch (Csla.DataPortalException
ex)
{
this.ErrorLabel.Text = ex.BusinessException.Message;
e.RowsAffected = 0;
}
catch (Exception ex)
{
this.ErrorLabel.Text = ex.Message
;
e.RowsAffected = 0;
}
}
// Function I use to fetch data. Uses SQL Query: Select * From Employee. Works just fine.
protected void EmployeesListDataSource_SelectObject(
object sender, Csla.Web.SelectObjectArgs e)
{
e.BusinessObject = GetEmployeesList();
}