We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

RowState of data source is incorrect

Hello,

I've bounded the GGC to datatable. After editing a row, the changes are applied to the underlying datarow of the edited record, but the row state is set to unchanged instead of modified.

I am using a CachingMode="ViewState".



Ive added an attachement look for at row state during updating event or any other point after the update.

Please advise.



WebApplication2_a08e015a.rar

5 Replies

RP Rekha P Syncfusion Team July 6, 2009 10:43 AM UTC

Hi Ruslan,

Thank you for your interest in Syncfusion Products.

We have analyzed more on the attached sample and found that database updation is cancelled in the RowUpdating event.

private void RowUpdating(object sender, GridDataSourceControlRowUpdateEventArgs e)
{
e.Cancel = true;
e.Handled = true;
}


The above code snippet will cancel the row update into the database and this is used for only sustaining the updated values only in the Grid control and not to the database and just it cancels the data update into underlying database. We would suggest you to remove "e.Cancel = true;". If you want to use a custom query to update, you have to write an event handler for the following event DataSourceControlRowUpdating.

Refer the Below code snippet.

protected void RowUpdating(object sender, GridDataSourceControlRowUpdateEventArgs e)
{
e.Cancel = true; //This will cancel the normal update in the datasource

//e will have all the values of the column in the Grid.
// your custom sql update query can be put up here.

e.Handled = true; //This will update the changes of the DataBase to the Grid.
}

Please let me know if you have any concerns.

Thanks,
Rekha


RG Ruslan Gasanbekov July 6, 2009 11:16 AM UTC

Hello,

10x for the reply.

I'm not sure I'm following you. I'll describe you what I'm trying to achieve (the datasource I'm using is DataTable):

1.User edits certain records via the grid.
2.The changes are applied to DataTable-grid's data source (still no update to DataBase at this point).
3.Then user continue to change/modify/delete entries at the grid.
(still no update to DataBase at this point).
4.User presses a button (some button on the screen) which creates TableAdapter and updates the DataBase accordingly to the values in DataTable - grid's datasource. Accordingly to each row state (added,deleted,modified) in the DataTable an appropriate stored procedute in TableAdapter is excecuted for this row.
(at this poing grid's datasource is the same as DataBase).

The bottom line is : I want to perform bulk update rather than separate update each time user finishes to modify a record.
So it essential for me to know what changes each row undergone - I know this via row state.


RP Rekha P Syncfusion Team July 8, 2009 11:33 AM UTC

Hi Ruslan,

In order to perform bulk update rather than separate update for each row, we would suggest you to use Excel-like Edit feature. The Essential Grid provides support for Excel-like Edit for all editable fields. This feature offers cell in-line editing, cell selection and row selection. Please have a look at the below online sample,

http://samples.syncfusion.com/ASPNET/7.2.0.37/web/grid.grouping.web/samples/3.5/CRUDOperations/ExcelLikeEdit/cs/excellikeedit.aspx

Since the ExcelEditMode works as a client side feature, the values can be updated into data base by manually. ExcelEditAutoUpdate property enables the AutoUpdate option for the updated values into the Grid and in order to update into data base, we need to manually retrieve the Grid rows and to update them. Please refer a code snippet to update Grid rows into data base via button click.

protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "";

SqlConnection sqlconnection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Suppliers.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand sqlcommand;
foreach (TableRow row in this.GridGroupingControl1.TopLevelTable.Rows)
{
if (row is GridRow)
{
GridRow gridRow = row as GridRow;
if (gridRow.Record != null)
{
sqlconnection.Open();
sqlcommand = new SqlCommand("UPDATE SuppliersData SET CompanyName = '" + gridRow.Record.GetValue("CompanyName").ToString() + "', ContactName = '" + gridRow.Record.GetValue("ContactName").ToString() + "', ContactTitle = '" + gridRow.Record.GetValue("ContactTitle").ToString() + "' WHERE SupplierID = '" + Convert.ToInt32(gridRow.Record.GetValue("SupplierID")) + "'", sqlconnection);
sqlcommand.ExecuteScalar();
sqlconnection.Close();
}
Label1.Text = "Updated into DataBase Successfully !!!";
}
}
}


The steps followed here are
1. Get the TableRow in the TopLevelTable.
2. Check if that Row is GridRow, if so Iterate the Gridcells.
3. Enable Update Command and update all the Grid rows.

Please refer a simple sample illustrating this feature.
http://files.syncfusion.com/support/GGC.Web/7.2.0.37/57355/Sample.zip

Let me know if this helps you out.

Thanks,
Rekha


AD Administrator Syncfusion Team July 8, 2009 12:18 PM UTC

10q for the answer - it helps :) .

Is there a way for me to know which rows undergone changes (I would like to update only those which has been modified, add only new rows, and delete only those which has been deleted by user)... ?

10x.


RP Rekha P Syncfusion Team July 14, 2009 12:03 PM UTC

Hi Ruslan,

Thank you for the update.

If your intension is to know the row state when it is created, added, modified, and deleted, we would suggest you use SelectedRecordsChanged event in which the SelectedRecordsChangedType enumeration is returned by the Action property of the SelectedRecords.

void GridGroupingControl1_SelectedRecordsChanged(object sender, SelectedRecordsChangedEventArgs e)
{
if (e.Action == SelectedRecordsChangedType.Added)
{

}
}

Also you can use GridRowEditUpdateLink's OnClick event to trigger GridRowEditUpdateEventArgs which determines the type of the CommandLink. The command link type can be checked for:

NewRecord,
Insert,
Delete,
Edit,
Update,
Cancel

Please refer the code snippet below to achieve this.

[ASPX]







[C#]

protected void RowEditUpdate(object sender, Syncfusion.Web.UI.WebControls.Grid.Grouping.GridRowEditUpdateEventArgs e)
{
Label1.Text = "";
if (e.CommandLinkType == "Update")
{
Label1.Text = "Update Link is clicked";
}
if (e.CommandLinkType == "Cancel")
{
Label1.Text = "Cancel Link is clicked";
}
if (e.CommandLinkType == "Edit")
{
Label1.Text = "Edit Link is clicked";
}
}


Sample:
http://files.syncfusion.com/support/GGC.Web/7.2.0.37/57673/Sample.zip

Please let me know if you have any concerns.

Thanks,
Rekha

Loader.
Live Chat Icon For mobile
Up arrow icon