<ej:Grid ID="Grid1" runat='server' DataMember="DefaultView" DataSourceID="SqlDataSource1" MinWidth="0" AllowSorting="True">
<Columns>
<ej:Column DataType="string" Field="Name" HeaderText="MENO" >
<NumericEditOptions Tag="" />
</ej:Column>
<ej:Column DataType="number" Field="Age" HeaderText="VEK" >
<NumericEditOptions Tag="" />
</ej:Column>
<ej:Column DataType="number" Field="Temp" HeaderText="TEMP" >
<NumericEditOptions Tag="" />
</ej:Column>
<ej:Column AllowEditing="False" DataType="number" Field="id" HeaderText="ID" IsIdentity="True" IsPrimaryKey="True" >
<NumericEditOptions Tag="" />
</ej:Column>
</Columns>
<PageSettings Template=""></PageSettings>
<EditSettings AllowEditing="True" />
</ej:Grid>
Thanks
Peter
Hi Peter,
Thanks for using Syncfusion products.
Query: I can edit cells but it is just in grid. It haven't affect in database.
We suggest you to use server side edit events (OnServerEditRow, OnServerAddRow, OnServerDeleteRow) and apply the edit changes from Grid to SQL database by using SQL commands to achieve your requirement. We can get the event arguments from the GridEventArgs class and perform edit operation based on its eventType. Please refer the below code snippet for further details.
[aspx]
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="SqlData" OnServerEditRow="EditEvents_ServerEditRow" OnServerAddRow="EditEvents_ServerAddRow" OnServerDeleteRow="EditEvents_ServerDeleteRow" MinWidth="0"> ------ ------ </ej:Grid>
[cs]
// Server side update record protected void EditEvents_ServerEditRow(object sender, GridEventArgs e) { EditAction(e.EventType, e.Arguments["data"]); } //Server side add record protected void EditEvents_ServerAddRow(object sender, GridEventArgs e) { EditAction(e.EventType, e.Arguments["data"]); } // Server side delete record protected void EditEvents_ServerDeleteRow(object sender, GridEventArgs e) { EditAction(e.EventType, e.Arguments["data"]); }
protected void EditAction(string eventType, object record) { Dictionary<string, object> KeyVal = record as Dictionary<string, object>; if (eventType == "endEdit") { ------- ------- }
else if (eventType == "endAdd") { -------- -------- }
else if (eventType == "endDelete") { ------- ------- } this.OrdersGrid.DataBind(); } |
Please refer the below online demo for further details.
Online Demo: http://asp.syncfusion.com/demos/web/grid/sqlbinding.aspx
For your convenience we have created a simple sample and the same can be downloaded from the below link.
Sample Link: http://www.syncfusion.com/downloads/support/directtrac/118467/SQLDataGrid305565162.zip
Please let us know if you have any concerns.
Regards,
Ajith R