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.
Unfortunately, activation email could not send to your email. Please try again.

Grouping Grid Example with DB Update

Thread ID:

Created:

Updated:

Platform:

Replies:

86860 Jul 9,2009 02:50 PM Jul 14,2009 08:23 AM ASP.NET Web Forms (Classic) 3
loading
Tags: GridGroupingControl
Administrator [Syncfusion]
Asked On July 9, 2009 02:50 PM

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.

Rekha P [Syncfusion]
Replied On July 10, 2009 09:36 AM

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

John Taylor
Replied On July 10, 2009 06:51 PM

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.



Rekha P [Syncfusion]
Replied On July 14, 2009 08:23 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;