尽管我讨厌回答自己的问题......
我不知道如何让这个控件做我想做的事。然而,一个简单的解决方法是处理 grid 本身的插入和更新。
所以,它现在可以工作了。我将LinqServerModeDataSource 上的EnableUpdate 和EnableInsert 属性设置为false,并简单地处理网格的RowInserting 和RowUpdating 事件,我直接进入数据库。
例如,我的插入事件处理程序是这样的:
protected void recipientsGrid_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
{
using (SqlConnection connection = new SqlConnection(App_Logic.Wrappers.DatabaseConnectionString()))
{
connection.Open();
using (SqlCommand command = new SqlCommand())
{
command.Connection = connection;
command.Transaction = connection.BeginTransaction();
try
{
command.CommandText = " INSERT INTO NotificationParty(NotificationGroupID, FirstName, LastName, CellNumber, Active, UserCreated, DateCreated) VALUES " +
"(@NotificationGroupID, @FirstName, @LastName, @CellNumber, @Active, @UserCreated, GETDATE())";
command.Parameters.AddWithValue("@NotificationGroupID", Convert.ToInt32(Context.Session["NotificationGroupID"]));
command.Parameters.AddWithValue("@FirstName", e.NewValues["FirstName"]);
command.Parameters.AddWithValue("@LastName", e.NewValues["LastName"]);
command.Parameters.AddWithValue("@CellNumber", e.NewValues["CellNumber"]);
command.Parameters.AddWithValue("@Active", 1);
command.Parameters.AddWithValue("@UserCreated", Session["UID"]);
command.ExecuteNonQuery();
command.Transaction.Commit();
}
catch
{
command.Transaction.Rollback();
}
}
}
recipientsGrid.CancelEdit();
e.Cancel = true;
}
我的更新事件处理程序是这样的:
protected void recipientsGrid_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
using (SqlConnection connection = new SqlConnection(App_Logic.Wrappers.DatabaseConnectionString()))
{
connection.Open();
using (SqlCommand command = new SqlCommand())
{
command.Connection = connection;
command.Transaction = connection.BeginTransaction();
try
{
command.CommandText = " UPDATE NotificationParty SET FirstName = @FirstName, LastName = @LastName, CellNumber = @CellNumber, UserModified = @UserModified, DateModified = GETDATE() WHERE ID = @ID";
command.Parameters.AddWithValue("@ID", e.Keys[0]);
command.Parameters.AddWithValue("@FirstName", e.NewValues["FirstName"]);
command.Parameters.AddWithValue("@LastName", e.NewValues["LastName"]);
command.Parameters.AddWithValue("@CellNumber", e.NewValues["CellNumber"]);
command.Parameters.AddWithValue("@UserModified", Session["UID"]);
command.ExecuteNonQuery();
command.Transaction.Commit();
}
catch
{
command.Transaction.Rollback();
}
}
}
recipientsGrid.CancelEdit();
e.Cancel = true;
}