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

Grouping Grid Example with DB Update

Are there any examples (I couldn't find any) of the Grouping Grid where the database is updated with changes? I'm looking for an example that uses stored procedures to perform the updates.

3 Replies

RP Rekha P Syncfusion Team July 10, 2009 01:36 PM UTC

Hi John,

Thank you for your interest in Syncfusion Products.

Please find a simple sample with stored procedures to perform the update operation in GridGroupingControl.

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

Thanks,
Rekha


JT John Taylor July 10, 2009 10:51 PM UTC

Thank you, Rekha.

Do you have anything that shows the process required to do the updates in code-behind? I'm not using the SqlDataSource controls.

I have my grid working for the display of data using a DataTable as the grid's DataSource, and a SqlDataAdapter to fill the Datatable. The problem I'm having is figuring out where to capture the updated grid records on postback, and how (if possible) to get the changed records back to database using SqlDataAdapter.

I had hoped that since DataSourceCachingMode="ViewState", I would be able to do something like:

DataTable dt = (DataTable)MyGrid.DataSource;
SqlDataAdapter da = new SqlDataAdapter();
da.UpdateCommand = GetUpdateCommand(conn);
da.InsertCommand = GetInsertCommand(conn);
da.DeleteCommand = GetDeleteCommand(conn);
da.SelectCommand = GetSelectCommand(conn);
da.Update(dt);

However, that doesn't work because it appears that RowState is not preserved when the control is serialized. All rows in the DataTable are in "Unchanged" state.




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

Hi John,

You can use your custom sql query in DataSourceControlRowUpdating event, which occurs before updating a record in the bound DataSourceControl. Please refer the sample code snippet below to achieve this.

protected void GridGroupingControl1_DataSourceControlRowUpdating(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.
}


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