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

Solution for simple drop and drag radgrid from one to another

1 Answer 38 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 02 Aug 2011, 08:51 PM

I am looking for a simple drag and drop solution from one radgrid that simply has a ssn and name to antoher grid that has positions that personnel can fill.  When I drag from the personnel grid to the position it automatically updates the radgrid with that person whom was droped in and fills it.  I was trying to use example on the site but they use a lot of datasource objects I cannot use, mine is straight code behind.  this is what I ahve so far but the drop is not working to the other radgrid.  I guess I am not getting the Id of the row I am draggging and I need to get the Id of where I drop it to save to the database.  Here is what I have what do i need to add or do differently.


 <table width="100%">
                    <tr>
                        <td align="center" valign="top">
                             <telerik:RadGrid ID="myGridPersonnel" runat="server" Width="100%" BorderWidth="1px" CellPadding="6" GridLines="None" BorderColor="#404040" Skin="Web20">
                                <ClientSettings AllowRowsDragDrop="true">
                                    <Selecting AllowRowSelect="true" EnableDragToSelectRows="false" />
                                </ClientSettings>
                                <MasterTableView AutoGenerateColumns="false" DataKeyNames="SSN_SM" GridLines="Both" BorderWidth="1px"
                                    BorderColor="#404040" Font-Size="12" Font-Names="Veranda,arial,sans-serif" HeaderStyle-HorizontalAlign="Center">
                                    <AlternatingItemStyle BackColor="#B0C4DE" />
                                    <HeaderStyle ForeColor="White" Font-Bold="true" BorderColor="#404040" BorderWidth="1px" />
                                        <Columns>
                                            <telerik:GridBoundColumn DataField="Name" HeaderText="NAME" />
                                        </Columns>
                                </MasterTableView>
                            </telerik:RadGrid>
                        </td>
                        <td align="center" valign="top">
                            <telerik:RadGrid ID="myGridPositions" runat="server" Width="100%" BorderWidth="1px" CellPadding="6" GridLines="None" BorderColor="#404040" Skin="Web20">
                                <ClientSettings AllowRowsDragDrop="true">
                                    <Selecting AllowRowSelect="true" EnableDragToSelectRows="false" />
                                </ClientSettings>
                                <MasterTableView AutoGenerateColumns="false" DataKeyNames="intPositionId" GridLines="Both" BorderWidth="1px"
                                    BorderColor="#404040" Font-Size="12" Font-Names="Veranda,arial,sans-serif" HeaderStyle-HorizontalAlign="Center">
                                    <AlternatingItemStyle BackColor="#B0C4DE" />
                                    <HeaderStyle ForeColor="White" Font-Bold="true" BorderColor="#404040" BorderWidth="1px" />
                                        <Columns>
                                            <telerik:GridBoundColumn DataField="strPosnTitle" HeaderText="TITLE" />
                                            <telerik:GridBoundColumn DataField="strpara" HeaderText="PARA" />
                                            <telerik:GridBoundColumn DataField="strLine" HeaderText="LINE" />
                                            <telerik:GridBoundColumn DataField="intPositionNum" HeaderText="POSITION" />
                                            <telerik:GridBoundColumn DataField="strGrade" HeaderText="GRADE" />
                                            <telerik:GridBoundColumn DataField="strMos" HeaderText="MOS" />
                                            <telerik:GridBoundColumn DataField="strFullName" HeaderText="Filled By" />
                                            <telerik:GridTemplateColumn HeaderText="Delete">
                                                <ItemTemplate>
                                                    <asp:LinkButton ID="Delete" runat="server" CommandArgument='<%# bind("intPositionId") %>' CommandName="Del">Delete</asp:LinkButton>
                                                </ItemTemplate>
                                            </telerik:GridTemplateColumn>
                                        </Columns>
                                </MasterTableView>
                            </telerik:RadGrid>
                        </td>
                    </tr>
                </table>


 Protected Sub myGridPersonnel_RowDrop(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridDragDropEventArgs) Handles myGridSoldier.RowDrop
        If String.IsNullOrEmpty(e.HtmlElement) Then
            If e.DraggedItems(0).OwnerGridID = myGridSoldier.ClientID Then
                Dim destinationIndex As Int32 = -1

                For Each dragged As GridDataItem In e.DraggedItems
                    Dim SSN As String = DirectCast(dragged.GetDataKeyValue("strssn"), String)
                    If SSN IsNot Nothing Then
                        If destinationIndex > -1 Then
                            If e.DropPosition = GridItemDropPosition.Below Then
                                destinationIndex += 1
                            End If
                            sql = "Insert tblMobUnitPersonnel (intpositionId, strssn) Values (45, " & SSN & ")"
                            Response.Write(sql)
                            Response.End()

                            insertUpdateDelete(sql)
                        Else

                        End If
                    End If
                Next
            End If
        End If
    End Sub

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 08 Aug 2011, 09:23 AM
Hello Kevin,

Do you rebind the second grid anywhere after inserting the new item in its datasource? Also, if you have ajax in this scenario, can you confirm that there are settings where each grid updates the other?

Generally, you could check if your logic works if you check the database itself to see whether the records have been inserted/deleted from the two tables. If not, try debugging your code to see what is the final look of the insert query string that you create to check whether all needed data is passed.

Additionally, indeed you should also have in mind the destination index when inserting data into the tables, because otherwise the second grid will not have the desired order but will always show the dropped items at the bottom/last page. 

Regards,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or