I have a grid control that allows the rows to be edited using a custom inline form. the data seems to be updated on the grid, however the data does not get saved to the table in the MySQL database.
I assumed that the grid engine would automatically update data via the bound source as it seems to do for new records, am I missing something?
NOTE: I can add new records correctly i.e. new data entered into grid appears in the database.
related information...
Datasource definition:
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:MySQLconnection %>"
ProviderName="<%$ ConnectionStrings:MySQLconnection.ProviderName %>"
SelectCommand="SELECT SENotes.* FROM SENotes WHERE GroupID = ?GroupID AND Client = ?Client AND Brand = ?Brand AND SearchEngine = ?SearchEngine AND ResultNo = ?ResultNo"
InsertCommand="INSERT INTO SENotes (GroupID, Client, Brand, SearchEngine, ResultNo, NoteDate, Author, Note) VALUES (?GroupID, ?Client, ?Brand, ?SearchEngine, ?ResultNo, CURDATE(), ?Author, ?Note)"
UpdateCommand="UPDATE SENotes SET Note = ?Note WHERE NoteNo = ?NoteNo AND GroupID = ?GroupID AND Client = ?Client AND Brand = ?Brand AND SearchEngine LIKE ?SearchEngine AND ResultNo = ?ResultNo" >
</asp:SqlDataSource>
Grid definition:
<syncfusion:GridGroupingControl ID="GridGroupingControl1" runat="server"
AutoSaveChildControlChanges="True" BorderCollapse="Separate"
ClientObjectID="__essentialGrid" DataSourceCachingMode="ViewState"
DataSourceID="SqlDataSource2" DragSelectionBackColor="Yellow"
EnableCallbacks="False" ShowGroupDropArea="False"
JsonActionMapper="JsonAction" ReCreateChildControls="False" SaveEmpty="True"
ShowWaitingPopupOnPostBack="True" AutoFormat="Navy Blue" Width="90%"
CssClass="GridNavyBlue" GroupDropAreaCssClass="GridNavyBlueGroupDropArea"
onbarbuttonitemclicked="GridGroupingControl1_BarButtonItemClicked" oncurrentrecordcontextchange="GridGroupingControl1_CurrentRecordContextChange" ondatasourcecontrolrowadded="GridGroupingControl1_DataSourceControlRowAdded">
<NestedTableGroupOptions AllowExpressionFilter="False"
FilterStatusBarWidth="450" ShowFilterStatusMessage="False" />
<Appearance>
<RecordPreviewCell CssClass="GridNavyBlueRecordPreview" />
<GroupHeaderRowHeaderCell CssClass="GridNavyBlueGroupedColumnHeaders" />
<ColumnHeaderCell CssClass="GridNavyBlueColumnHeaders" />
<TopLeftHeaderCell CssClass="GridNavyBlueTopLeftHeaderCell" />
<RowHeaderCell CssClass="GridNavyBlueRowHeaders" />
<AnyRecordFieldCell CssClass="GridNavyBlueAnyRecord" />
<AlternateRecordFieldCell CssClass="GridNavyBlueAlternateRecord" />
<GroupIndentCell CssClass="GridNavyBlueGroupIndentCell" />
<GroupCaptionCell CssClass="GridNavyBlueGroupCaption" />
<GroupCaptionPlusMinusCell CssClass="GridNavyBluePlusMinus" />
<FilterBarCell CssClass="GridNavyBlueFilterBarCell" />
<AnySummaryCell CssClass="GridNavyBlueAnySummary" />
</Appearance>
<PageManager EnableOnDemandPaging="False" TotalRecordsCount="5" />
<TableDescriptor GroupExpandImage="" FormEditMode="UseInlineForm"
AllowRemove="false" AllowEdit="true" AllowNew="true" >
<InlineFormModeTemplate>
<span><b>Notes</b></span>
<div style="text-align:center">
<asp:TextBox ID="txtNotes" runat="server" TextMode="MultiLine" Height="50px" Width="90%" Text='<%#GetFieldValue("Note", Container)%>'></asp:TextBox>
</div>
</InlineFormModeTemplate>
<VisibleColumns>
<syncfusion:GridVisibleColumnDescriptor Name="NoteDate" />
<syncfusion:GridVisibleColumnDescriptor Name="Author" />
<syncfusion:GridVisibleColumnDescriptor Name="Note" />
</VisibleColumns>
<Columns>
<syncfusion:GridColumnDescriptor MappingName="GroupID" HeaderText="Group">
<GroupByOptions AllowExpressionFilter="False" FilterStatusBarWidth="450"
ShowFilterStatusMessage="False" />
</syncfusion:GridColumnDescriptor>
<syncfusion:GridColumnDescriptor MappingName="Client" HeaderText="Client">
<GroupByOptions AllowExpressionFilter="False" FilterStatusBarWidth="450"
ShowFilterStatusMessage="False" />
</syncfusion:GridColumnDescriptor>
<syncfusion:GridColumnDescriptor MappingName="Brand" HeaderText="Brand">
<GroupByOptions AllowExpressionFilter="False" FilterStatusBarWidth="450"
ShowFilterStatusMessage="False" />
</syncfusion:GridColumnDescriptor>
<syncfusion:GridColumnDescriptor MappingName="SearchEngine" HeaderText="Search Engine">
<GroupByOptions AllowExpressionFilter="False" FilterStatusBarWidth="450"
ShowFilterStatusMessage="False" />
</syncfusion:GridColumnDescriptor>
<syncfusion:GridColumnDescriptor MappingName="ResultNo" HeaderText="Result ID">
<GroupByOptions AllowExpressionFilter="False" FilterStatusBarWidth="450"
ShowFilterStatusMessage="False" />
</syncfusion:GridColumnDescriptor>
<syncfusion:GridColumnDescriptor MappingName="NoteNo" HeaderText="Note ID">
<GroupByOptions AllowExpressionFilter="False" FilterStatusBarWidth="450"
ShowFilterStatusMessage="False" />
</syncfusion:GridColumnDescriptor>
<syncfusion:GridColumnDescriptor MappingName="NoteDate" HeaderText="Date" Width="75">
<Appearance>
<AnyRecordFieldCell CellValueType="System.DateTime" Format="dd/MMM/yyyy" AutoSize="false"/>
</Appearance>
<GroupByOptions AllowExpressionFilter="False" FilterStatusBarWidth="450"
ShowFilterStatusMessage="False" />
</syncfusion:GridColumnDescriptor>
<syncfusion:GridColumnDescriptor MappingName="Author" HeaderText="Author" Width="125">
<GroupByOptions AllowExpressionFilter="False" FilterStatusBarWidth="450"
ShowFilterStatusMessage="False" />
<ItemTemplate>
<asp:Label ID="lblAuthor" BackColor="Transparent" runat="server" Text='<%# GetAuthor( Container.DataItem )%>'></asp:Label>
</ItemTemplate>
</syncfusion:GridColumnDescriptor>
<syncfusion:GridColumnDescriptor MappingName="Note" HeaderText="Note" Appearance-AnyHeaderCell-TextAlign="Left" Appearance-AnyRecordFieldCell-TextAlign="left" Appearance-AnyRecordFieldCell-MaxLength="50" Appearance-AnyRecordFieldCell-Trimming="EllipsisCharacter" Appearance-AnyRecordFieldCell-WrapText="false" >
<GroupByOptions AllowExpressionFilter="False" FilterStatusBarWidth="450"
ShowFilterStatusMessage="False" />
<Appearance>
<AnyRecordFieldCell MaxLength="50" TextAlign="Left"
Trimming="EllipsisCharacter" WrapText="False" />
</Appearance>
</syncfusion:GridColumnDescriptor>
</Columns>
<EditFormSettings FormEditMode="UseInlineTemplateForm">
</EditFormSettings>
<ChildGroupOptions AllowExpressionFilter="False" FilterStatusBarWidth="450"
ShowFilterStatusMessage="False" />
<TopLevelGroupOptions AllowExpressionFilter="False" FilterStatusBarWidth="450"
ShowFilterStatusMessage="False" />
</TableDescriptor>
<ChildGroupOptions AllowExpressionFilter="False" FilterStatusBarWidth="450"
ShowFilterStatusMessage="False" />
<TopLevelGroupOptions AllowExpressionFilter="False" FilterStatusBarWidth="450"
ShowFilterStatusMessage="False" ShowAddNewRecordAfterDetails="true" ShowAddNewRecordBeforeDetails="false" ShowCaption="false" />
<ButtonBars>
<syncfusion:NavigatorBar ButtonBackColor="">
<BarItems>
<syncfusion:ButtonBarItem ButtonBarItemType="MoveFirst">
</syncfusion:ButtonBarItem>
<syncfusion:ButtonBarItem ButtonBarItemType="MovePrevPage">
</syncfusion:ButtonBarItem>
<syncfusion:ButtonBarItem ButtonBarItemType="MovePrev">
</syncfusion:ButtonBarItem>
<syncfusion:ButtonBarItem ButtonBarItemType="MoveNext">
</syncfusion:ButtonBarItem>
<syncfusion:ButtonBarItem ButtonBarItemType="MoveNextPage">
</syncfusion:ButtonBarItem>
<syncfusion:ButtonBarItem ButtonBarItemType="MoveLast">
</syncfusion:ButtonBarItem>
<syncfusion:ButtonBarItem ButtonBarItemType="EditRow">
</syncfusion:ButtonBarItem>
<syncfusion:ButtonBarItem ButtonBarItemType="Refresh">
</syncfusion:ButtonBarItem>
<syncfusion:ButtonBarItem ButtonBarItemType="Save">
</syncfusion:ButtonBarItem>
<syncfusion:ButtonBarItem ButtonBarItemType="Cancel">
</syncfusion:ButtonBarItem>
</BarItems>
</syncfusion:NavigatorBar>
</ButtonBars>
</syncfusion:GridGroupingControl>
SQL table definition:
CREATE TABLE `SENotes` (
`NoteNo` bigint(20) NOT NULL AUTO_INCREMENT,
`GroupID` int(11) NOT NULL,
`Client` int(11) NOT NULL,
`Brand` int(11) NOT NULL,
`SearchEngine` varchar(45) NOT NULL,
`ResultNo` int(11) NOT NULL,
`NoteDate` date DEFAULT NULL,
`Author` bigint(20) DEFAULT NULL,
`Note` text,
PRIMARY KEY (`NoteNo`,`GroupID`,`Client`,`Brand`,`SearchEngine`,`ResultNo`),
KEY `FK_results_idx` (`NoteNo`,`GroupID`,`Client`,`Brand`,`SearchEngine`,`ResultNo`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1$$
Code Behind:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using MySql.Data.MySqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Configuration;
using System.Xml.Linq;
using Syncfusion.Web.UI.WebControls.Grid.Grouping;
using Syncfusion.Grouping;
namespace Online
{
public partial class ResultsMoreInfo : System.Web.UI.Page
{
private int theClient;
private int theBrand;
private int theResultNo;
private string theSearchEngine;
private DataTable dtResults = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
theClient = Convert.ToInt32(Request.Params["client"]);
theBrand = Convert.ToInt32(Request.Params["brand"]);
theResultNo = Convert.ToInt32(Request.Params["ResultNo"]);
theSearchEngine = Request.Params["SearchEngine"];
// Load SE monitoring result for requsted line
//
string strFilterCriteria = "GroupID = " + PortalData.mGroupID + " AND Client = " + theClient + " AND Brand = " + theBrand + " AND `Search Engine` LIKE '" + theSearchEngine + "' AND ResultNo = " + theResultNo;
dtResults = PortalData.GetTableData("SEMonitoringResults", strFilterCriteria);
if (dtResults.Rows.Count > 0)
{
SqlDataSource1.SelectParameters.Add("GroupID", DbType.Int32, PortalData.mGroupID.ToString());
SqlDataSource1.SelectParameters.Add("Client", DbType.Int32, theClient.ToString());
SqlDataSource1.SelectParameters.Add("Brand", DbType.Int32, theBrand.ToString());
SqlDataSource1.SelectParameters.Add("SearchEngine", DbType.String, theSearchEngine);
SqlDataSource1.SelectParameters.Add("ResultNo", DbType.Int32, theResultNo.ToString());
SqlDataSource2.SelectParameters.Add("GroupID", DbType.Int32, PortalData.mGroupID.ToString());
SqlDataSource2.SelectParameters.Add("Client", DbType.Int32, theClient.ToString());
SqlDataSource2.SelectParameters.Add("Brand", DbType.Int32, theBrand.ToString());
SqlDataSource2.SelectParameters.Add("SearchEngine", DbType.String, theSearchEngine);
SqlDataSource2.SelectParameters.Add("ResultNo", DbType.Int32, theResultNo.ToString());
txtWhois.Text = dtResults.Rows[0]["WhoisData"].ToString();
txtISP.Text = dtResults.Rows[0]["ISP"].ToString();
chkFirstSeen.Checked = false;
}
}
/// <summary>
/// Used in the aspx file to get the field value of a record.
/// </summary>
/// <param name="fieldName"></param>
/// <param name="container"></param>
/// <returns></returns>
protected string GetFieldValue(string fieldName, GridFormEditCell container)
{
Record editRecord = container.CurrentRecord;
return editRecord.GetValue(fieldName).ToString();
}
protected string GetAuthor(object pData)
{
Record dr = pData as Record;
if (dr["Author"] != null)
return PortalData.GetName((long)dr["Author"]);
else
return null;
}
protected void GridGroupingControl1_CurrentRecordContextChange(object sender, Syncfusion.Grouping.CurrentRecordContextChangeEventArgs e)
{
if (e.Record != null)
//When creating a new record
//
if (e.Record.Kind == Syncfusion.Grouping.DisplayElementKind.AddNewRecord && e.Action == Syncfusion.Grouping.CurrentRecordAction.EndEditCalled)
{
e.Table.AddNewRecord.SetValue("GroupID", PortalData.mGroupID);
e.Table.AddNewRecord.SetValue("Client", theClient);
e.Table.AddNewRecord.SetValue("Brand", theBrand);
e.Table.AddNewRecord.SetValue("SearchEngine", theSearchEngine);
e.Table.AddNewRecord.SetValue("ResultNo", theResultNo);
//e.Table.AddNewRecord.SetValue("NoteNo", this.GridGroupingControl1.CurrentTable.GetFilteredRecordCount() + 1);
e.Table.AddNewRecord.SetValue("Author", PortalData.mUserID);
}
}
protected void GridGroupingControl1_BarButtonItemClicked(object source, ButtonBarItemClickEventArgs e)
{
txtErrorMessage.Text = "";
if (this.GridGroupingControl1.TableDescriptor.FormEditMode != TableEditMode.UseTemplateForm && this.GridGroupingControl1.TableDescriptor.FormEditMode != TableEditMode.UseInlineTemplateForm)
return;
if (e.ButtonBarItem.ButtonBarItemType == ButtonBarItemType.EditRow)
{
this.GridGroupingControl1.Table.AddNew();
}
if (e.ButtonBarItem.ButtonBarItemType == ButtonBarItemType.Save)
{
Record curRecord = this.GridGroupingControl1.FormEditCell.CurrentRecord;
TextBox tb;
tb = this.GridGroupingControl1.FormEditCell.FindControl("txtNotes") as TextBox;
curRecord.SetValue("Note", tb.Text);
this.GridGroupingControl1.Table.EndEdit();
e.Handled = true;
}
}
protected void GridGroupingControl1_DataSourceControlRowAdded(object sender, GridDataSourceControlRowAddedEventArgs e)
{
//Update Grid Display
//
UpdatePanel1.Update();
SqlDataSource2.SelectParameters.Clear();
SqlDataSource2.SelectParameters.Add("GroupID", DbType.Int32, PortalData.mGroupID.ToString());
SqlDataSource2.SelectParameters.Add("Client", DbType.Int32, theClient.ToString());
SqlDataSource2.SelectParameters.Add("Brand", DbType.Int32, theBrand.ToString());
SqlDataSource2.SelectParameters.Add("SearchEngine", DbType.String, theSearchEngine);
SqlDataSource2.SelectParameters.Add("ResultNo", DbType.Int32, theResultNo.ToString());
this.GridGroupingControl1.DataBind();
}
}
}