This is a migrated thread and some comments may be shown as answers.

how to Bind & Perform DML(Insert/Update/Delete) operations for the following scenario..

1 Answer 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ranganath
Top achievements
Rank 1
Ranganath asked on 08 Sep 2008, 02:45 PM

Hi,

Please guide me how to Bind & Perform DML(Insert/Update/Delete) operations for the following scenario..

The following Example I implemented on NorthWind Database.

<

table cellpadding="0" cellspacing="0" width="100%" border="1" style="border-color: Green">

<tr>

<td>

<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Default" Width="95%" AutoGenerateColumns="False"

PageSize="5" AllowSorting="True" AllowPaging="True" AllowAutomaticUpdates="True"

AllowAutomaticInserts="True" AllowAutomaticDeletes="True"

ShowStatusBar="true" onitemcreated="RadGrid1_ItemCreated"

onitemdatabound="RadGrid1_ItemDataBound"

onneeddatasource="RadGrid1_NeedDataSource">

<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>

<MasterTableView SkinID="Default" DataKeyNames="EmployeeID"

AllowMultiColumnSorting="True" AllowAutomaticDeletes="true" AllowAutomaticUpdates="true"

AllowAutomaticInserts="true">

<DetailTables>

<telerik:GridTableView SkinID="Default" DataKeyNames="EmployeeID, OrderID" DataSourceID="nestedTableSource" Name="GrdTableView" Width="100%"

runat="server" AllowAutomaticDeletes="true" AllowAutomaticInserts="true" AllowAutomaticUpdates="true"

CommandItemDisplay="Top">

<ParentTableRelation>

<telerik:GridRelationFields DetailKeyField="EmployeeID" MasterKeyField="EmployeeID" />

</ParentTableRelation>

<Columns>

<telerik:GridBoundColumn SortExpression="OrderID" HeaderText="OrderID" HeaderButtonType="TextButton"

DataField="OrderID" UniqueName="OrderID" ReadOnly="true">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn SortExpression="ShipVia" HeaderText="Ship via" HeaderButtonType="TextButton"

DataField="ShipVia" UniqueName="ShipVia">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn SortExpression="ShipName" HeaderText="Ship name" HeaderButtonType="TextButton"

DataField="ShipName" UniqueName="ShipName">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn SortExpression="ShipCity" HeaderText="Ship city" HeaderButtonType="TextButton"

DataField="ShipCity" UniqueName="ShipCity">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn SortExpression="ShipCountry" HeaderText="Ship country" HeaderButtonType="TextButton"

DataField="ShipCountry" UniqueName="ShipCountry">

</telerik:GridBoundColumn>

<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />

<telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete" />

</Columns>

</telerik:GridTableView>

</DetailTables>

<Columns>

<telerik:GridBoundColumn SortExpression="EmployeeID" HeaderText="EmployeeID" HeaderButtonType="TextButton"

DataField="EmployeeID" UniqueName="EmployeeID" ReadOnly="true">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn SortExpression="FirstName" HeaderText="First name" HeaderButtonType="TextButton"

DataField="FirstName" UniqueName="FirstName">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn SortExpression="LastName" HeaderText="Last name" HeaderButtonType="TextButton"

DataField="LastName" UniqueName="LastName">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn SortExpression="Address" HeaderText="Address" HeaderButtonType="TextButton"

DataField="Address" UniqueName="Address">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn SortExpression="City" HeaderText="City" HeaderButtonType="TextButton"

DataField="City" UniqueName="City" />

<telerik:GridBoundColumn SortExpression="Country" HeaderText="Country" HeaderButtonType="TextButton"

DataField="Country" UniqueName="Country">

</telerik:GridBoundColumn>

</Columns>

</MasterTableView>

</telerik:RadGrid>

<asp:SqlDataSource ID="nestedTableSource" SelectCommand="SELECT [OrderID],[EmployeeID], [ShipVia], [ShipName], [ShipCity], [ShipCountry] FROM [Orders] WHERE ([EmployeeID] = @EmployeeID)"

runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"

DeleteCommand="DELETE FROM [Orders] WHERE [OrderID] = @original_OrderID" InsertCommand="INSERT INTO [Orders] ([EmployeeID], [ShipVia], [ShipName], [ShipCity], [ShipCountry]) VALUES (@EmployeeID, @ShipVia, @ShipName, @ShipCity, @ShipCountry)"

OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [Orders] SET [ShipVia] = @ShipVia, [ShipName] = @ShipName, [ShipCity] = @ShipCity, [ShipCountry] = @ShipCountry WHERE [OrderID] = @original_OrderID AND [ShipVia] = @original_ShipVia AND [ShipName] = @original_ShipName AND [ShipCity] = @original_ShipCity AND [ShipCountry] = @original_ShipCountry">

<SelectParameters>

<asp:SessionParameter Name="EmployeeID" SessionField="EmployeeID" Type="Int32" Direction="Input" />

</SelectParameters>

<DeleteParameters>

<asp:Parameter Name="original_OrderID" Type="Int32" />

</DeleteParameters>

<UpdateParameters>

<asp:Parameter Name="ShipVia" Type="Int32" />

<asp:Parameter Name="ShipName" Type="String" />

<asp:Parameter Name="ShipCity" Type="String" />

<asp:Parameter Name="ShipCountry" Type="String" />

<asp:Parameter Name="original_OrderID" Type="Int32" />

<asp:Parameter Name="original_ShipVia" Type="Int32" />

<asp:Parameter Name="original_ShipName" Type="String" />

<asp:Parameter Name="original_ShipCity" Type="String" />

<asp:Parameter Name="original_ShipCountry" Type="String" />

</UpdateParameters>

<InsertParameters>

<asp:SessionParameter Name="EmployeeID" SessionField="EmployeeID" Type="Int32" />

<asp:Parameter Name="ShipVia" Type="Int32" />

<asp:Parameter Name="ShipName" Type="String" />

<asp:Parameter Name="ShipCity" Type="String" />

<asp:Parameter Name="ShipCountry" Type="String" />

</InsertParameters>

</asp:SqlDataSource>

</td>

</tr>

</table>

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Sep 2008, 07:41 AM
Hi,

Check out the demo link below to perform automatic operations  in grid.
http://demos.telerik.com/ASPNET/Prometheus/Grid/Examples/DataEditing/AllEditableColumns/DefaultCS.aspx


Thanks,
Princy
Tags
Grid
Asked by
Ranganath
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or