Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
175
WebDataGrid - where do I look for data changes made by the user?
posted

We have a WebDataGrid of BoundDataField columns that is intended to allow the user to update existing rows in the database (adding and deleting rows is not required). We want to update the database using our own custom code, so we have AutoCRUD=false. The user can change the data in any column of any row by typing a new value directly into the corresponding cell of the grid. In other words, we don't use a popup dialog (like RowEditingTemplate provides) to edit the data. We prefer to let the user edit the data directly in the cells of the grid. The grid is accepting the user's changes on the client-side (we know because we've written test Javascript to prove this), but when the form containing the grid is submitted, we don't see the user's changes on the server-side. Where should we be looking for those changes? We have been looking for them in myGrid.Rows but they are not there. We have tried setting EnableViewState to both true and false but neither works. Having EnableViewState=true seems to just overwrite the user's changes with the data that was in the grid when it was last sent to the client. Having EnableViewState=false causes the error described here http://www.infragistics.com/community/forums/t/47016.aspx.
The user's changes must be getting passed to the server somehow (why else would the grid allow editing), but where are they?

  • 16310
    Offline posted

    Hello Michael,

    You have properly set AutoCRUD = false since you wish to manually handle all updates. The grid editing behavior provides the corresponding server side events where this should happen. When dealing with editing, we need to handle the server side RowUpdating event:

        OnRowUpdating="wdg1_RowUpdating" 
        OnRowAdding="wdg1_RowAdding" 
        OnRowsDeleting="wdg1_RowsDeleting">

    In C#:

        protected void WebDataGrid1_RowUpdating(object sender, Infragistics.Web.UI.GridControls.RowUpdatingEventArgs e)
        {
            DataTable table = (DataTable)Session["data"];

            var row = table.Rows.Find(e.Row.DataKey);

            row["Item"] = e.Values["Item"];
            row["Data"] = e.Values["Data"];
            table.AcceptChanges();

            Session["data"] = table;

            this.WebDataGrid1.DataSource = table;
            this.WebDataGrid1.DataBind();
        }

    where the event arguments contain the modified data and you can access it as shown above. The recommended approach is to apply the modified data not to the grid rows, but to the grid data source as shown above and then rebind the grid. This sample code handle updates to a DataTable, so if you have an sql database you will need to initiate a connection in this event and execute query to the database.

    You can review the following video on how to setup a manual crud scenario or this blog post.

    Please let me know if you would like me to send you a simple sample that demonstrates a manual crud scenario that you can benefit from.