In WebGrid, you can perform update to the Database after you have finished changes WebGrid's data.
In this topic, you will learn how to perform update to the Database using button click after modification through the WebGrid's data is done.
To perform Bulk Update
- Bind WebGrid to ISDataSource.
- Set WebGrid's AllowEdit, AllowDelete, AllowAddNew On the InitializeLayout server side event.
- Set ISDataSource's EnableCaching to Yes.
C# Copy Code protected void WebGrid1_InitializeLayout(object sender, ISNet.WebUI.WebGrid.LayoutEventArgs e)
{
e.Layout.AllowEdit = ISNet.WebUI.WebGrid.Edit.Yes;
e.Layout.AllowDelete = ISNet.WebUI.WebGrid.Delete.Yes;
e.Layout.AllowAddNew = ISNet.WebUI.WebGrid.AddNew.Yes;
}
- In the UpdateRow, AddRow, DeleteRow server side WebGrid event, set the return value to false so the record will be marked as dirty and will be updated later on.
C# Copy Code protected void WebGrid1_AddRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e)
{
e.ReturnValue = false;
}
protected void WebGrid1_DeleteRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e)
{
e.ReturnValue = false;
}
protected void WebGrid1_UpdateRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e)
{
e.ReturnValue = false;
}
- Finally, put the following code in Button Click function to apply update from Database.
C# Copy Code protected void Button1_Click(object sender, EventArgs e)
{
DataView view = this.ISDataSource1.Select("Customers") as DataView;
NorthWind.CustomersDataTable table = view.Table as NorthWind.CustomersDataTable;
table.AcceptChanges();
NorthWindTableAdapters.CustomersTableAdapter da = new NorthWindTableAdapters.CustomersTableAdapter();
da.Update(table);
}
Tasks
Walkthrough: Using MultiLine TextBox
Walkthrough: Using CheckBox
Walkthrough: Using Calendar DropDown
Walkthrough: Using Calendar Combo
How-to: Use DropDownList as EditType of a WebGridColumn
References
AllowDelete Property
AllowEdit Property
AllowAddNew Property
InitializeLayout Event
AddRow Event
DeleteRow Event
UpdateRow Event
ButtonClick Event
Other Resources
Walkthrough Topics
How-to Topics