Intersoft WebGrid Documentation
How-to: Perform Bulk Update on a Button Click event
See Also Send comments on this topic.

Glossary Item Box

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

  1. Bind WebGrid to ISDataSource.
  2. Set WebGrid's AllowEdit, AllowDelete, AllowAddNew On the InitializeLayout server side event.
  3. 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;
    }

  4. 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 ImageCopy 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;
    }

  5. 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);
    }

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.