Creating the server-side methods
Each method must have two arguments. The first argument is of type Object and
represents the Grid object which triggered the event. The second argument is
of type GridRecordEventArgs and contains the data that must be stored in
the database.
C#
void DeleteRecord(object sender, GridRecordEventArgs e)
{
NorthwindDataContext db = new NorthwindDataContext();
var cust = (from c in db.Customers
where c.CustomerID == e.Record["CustomerID"].ToString()
select c).First();
db.Customers.DeleteOnSubmit(cust);
db.SubmitChanges();
}
void UpdateRecord(object sender, GridRecordEventArgs e)
{
NorthwindDataContext db = new NorthwindDataContext();
var cust = (from c in db.Customers
where c.CustomerID == e.Record["CustomerID"].ToString()
select c).First();
cust.ContactName = e.Record["ContactName"].ToString();
cust.CompanyName = e.Record["CompanyName"].ToString();
cust.City = e.Record["City"].ToString();
cust.Country = e.Record["Country"].ToString();
db.SubmitChanges();
}
void InsertRecord(object sender, GridRecordEventArgs e)
{
NorthwindDataContext db = new NorthwindDataContext();
Customer c = new Customer()
{
CustomerID = e.Record["CustomerID"].ToString(),
ContactName = e.Record["ContactName"].ToString(),
CompanyName = e.Record["CompanyName"].ToString(),
City = e.Record["City"].ToString(),
Country = e.Record["Country"].ToString()
};
db.Customers.InsertOnSubmit(c);
db.SubmitChanges();
}
void RebindGrid(object sender, EventArgs e)
{
// re-create the grid from the updated database
}
VB
Sub DeleteRecord(sender As Object, e As GridRecordEventArgs)
Dim db As New NorthwindDataContext()
Dim cust = (From c In db.Customers Where c.CustomerID = e.Record("CustomerID").ToString() Select c).First()
db.Customers.DeleteOnSubmit(cust)
db.SubmitChanges()
End Sub
Sub UpdateRecord(sender As Object, e As GridRecordEventArgs)
Dim db As New NorthwindDataContext()
Dim cust = (From c In db.Customers Where c.CustomerID = e.Record("CustomerID").ToString() Select c).First()
cust.ContactName = e.Record("ContactName").ToString()
cust.CompanyName = e.Record("CompanyName").ToString()
cust.City = e.Record("City").ToString()
cust.Country = e.Record("Country").ToString()
db.SubmitChanges()
End Sub
Sub InsertRecord(sender As Object, e As GridRecordEventArgs)
Dim db As New NorthwindDataContext()
Dim c As New Customer() With {
.CustomerID = e.Record("CustomerID").ToString(),
.ContactName = e.Record("ContactName").ToString(),
.CompanyName = e.Record("CompanyName").ToString(),
.City = e.Record("City").ToString(),
.Country = e.Record("Country").ToString()
}
db.Customers.InsertOnSubmit(c)
db.SubmitChanges()
End Sub
Sub RebindGrid(sender As Object, e As EventArgs)
' re-create the grid from the updated database
End Sub
Important
After each change made to the database, if Serialize is set to true,
the grid should be recreated.The OnRebind event is used for this action.