473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Drag and drop works dragging down but not up

dbrewerton
115 100+
Hey experts, I have this vb.net code that allows me to drag and drop between gridviews that are dynamically produced from the database in a downward direction but will not do that for dragging up. For example, I can drag to department2 from department1 but it will nto let me drag department2 to department1. My aspx page only contains two literal controls as placeholders for the gridview and JQuery produced by the code. Here is my code:
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2. Imports System.Data
  3.  
  4. Partial Class Training_tree_DragDropOrg
  5.     Inherits System.Web.UI.Page
  6.  
  7.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  8.  
  9.         If Not IsPostBack Then
  10.  
  11.             Dim args As New DataSourceSelectArguments
  12.             Dim dsDivisions As New DataView
  13.             Dim dsDepartments As New DataView
  14.             Dim drDivision As DataRow
  15.             Dim drDepartment As DataRow
  16.             Dim strDepts As String = ""
  17.             Dim strLIDepts As String = ""
  18.             Dim strOLDepts As String = ""
  19.             SqlDataSourceDivisions.SelectCommand = "Select id, Name from Divisions"
  20.             dsDivisions = SqlDataSourceDivisions.Select(args)
  21.  
  22.             If dsDivisions.Table.Rows.Count > 0 Then
  23.  
  24.                 Literal1.Text = ""
  25.                 Dim x As Integer
  26.                 For x = 0 To dsDivisions.Table.Rows.Count - 1
  27.                     drDivision = dsDivisions.Table.Rows(x)
  28.                     Literal1.Text += "<div id='" & drDivision.Item("ame").ToString & "'>"
  29.                     Literal1.Text += "<h1 class='ui-widget-header'>"
  30.                     Literal1.Text += "<h1>" & drDivision.Item("Name").ToString & "</h1>"
  31.                     Literal1.Text += "<div class='ui-widget-content'>"
  32.                     Literal1.Text += "<ol  id='list" & drDivision.Item("Name").ToString & "'>"
  33.  
  34.                     SqlDataSourceDepartments.SelectCommand = "Select id, Name from Departments where DivisionID = " & drDivision.Item("id") & " union select ' ', '&nbsp;&nbsp;&nbsp; '"
  35.                     dsDepartments = SqlDataSourcedepartments.Select(args)
  36.  
  37.                     If dsDepartments.Table.Rows.Count > 0 Then
  38.                         Dim y As Integer
  39.                         Literal1.Text += "<ul id = 'li" & drDivision.Item("Name").ToString & "'  class='" & drDivision.Item("id").ToString & "'>"
  40.  
  41.                         For y = 0 To dsDepartments.Table.Rows.Count - 1
  42.                             drDepartment = dsDepartments.Table.Rows(y)
  43.                             Literal1.Text += "<li >" & drDepartment.Item("Name").ToString & "</li>"
  44.                         Next
  45.                         Literal1.Text += "</ul>"
  46.  
  47.  
  48.                         Literal1.Text += "</ol></div>"
  49.  
  50.                     End If
  51.  
  52.                     strDepts += "#" & drDivision.Item("Name") & ","
  53.                     strLIDepts += "#" & drDivision.Item("Name") & ".li ,"
  54.                     strOLDepts += "#list" & drDivision.Item("Name") & ","
  55.  
  56.                 Next
  57.  
  58.                 Literal1.Text += "</div>"
  59.                 strDepts += strDepts.Substring(0, strDepts.Length - 1)
  60.                 strLIDepts += strLIDepts.Substring(0, strLIDepts.Length - 1)
  61.                 strOLDepts += strOLDepts.Substring(0, strOLDepts.Length - 1)
  62.  
  63.             End If
  64.             LiteralScript.Text = " <script type='text/javascript'>   $(function () {"
  65.             LiteralScript.Text += " $('" & strLIDepts & "').draggable({appendTo: 'body', helper: 'clone' });"
  66.             LiteralScript.Text += " $('" & strDepts & "').droppable( {  activeClass: 'ui-state-default',  hoverClass: 'ui-state-hover',drop: function (event, ui){"
  67.             LiteralScript.Text += "var selected = $('" & strOLDepts & "').find("":contains('"" + ui.draggable.text() + ""')"");"
  68.             LiteralScript.Text += " var li = selected[1];  var ol = selected[0];  if(selected.length >0){ ol.removeChild(li); this.appendChild(li);}}}).sortable({items:'li:not(.placeholder)'});"
  69.             Literal1.Text += "</ol></div>"
  70.             LiteralScript.Text += " });</script> "
  71.  
  72.         End If
  73.  
  74.     End Sub
  75. End Class
Apr 16 '14 #1
1 1161
dbrewerton
115 100+
Done a bit more tweaking, this one allows drag up and down but gives me an error. When I drop the item to move, I get this error:

Expand|Select|Wrap|Line Numbers
  1. Line: 113
  2. Error: Unable to get value of the property 'appendChild': object is null or undefined
Here is the code as it stands now:

Expand|Select|Wrap|Line Numbers
  1. <script type='text/javascript'>$(function () {
  2. $('" & strLIDepts & "').draggable();
  3.  $('" & strOLDepts & "').droppable( {  activeClass: 'ui-state-default',  hoverClass: 'ui-state-hover' ,drop: function (event, ui){
  4. var selected = $('" & strDepts & "').find("":contains('"" + ui.draggable.text() + ""')"");
  5. if (selected.length > 0) { var ol = selected[1]; var li = selected[3]; var oldList = ol.children('li' + ol.id); if(oldList){ oldList.removeChild(li);} 
  6.  else{ ol =selected[3]; alert(ol.id); li=selected[4] ;  ol.removeChild(li);  }}
  7. var newItem = document.createElement('li'); var newItemValue = document.createTextNode(ui.draggable.text()); newItem.appendChild(newItemValue); this.children('li' + this.id).appendChild(newItem);
  8.   }}).sortable({items:'li'});
  9. });
  10. </script>
  11.  
Apr 22 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: simon_s_li | last post by:
Hi, I have 5 fields in line where I need to drag and drop the text from one field to another field and then all the fields need to re-order themselves. So for instance if I drag the text in...
2
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put...
14
by: Nathan | last post by:
I'm working for the first time with the DoDragDrop method. I've got almost everything worked out, but I need some help with the last bit. There are two listboxes on my form, lstGroups and...
1
by: Kevin L | last post by:
I have a Panel control that I currently allow the user to drag and reposition on a form at runtime. This Panel control contains a Label control. I would like to allow the user to drag the PANEL...
0
by: Pesso | last post by:
I'm loading a text file to a RichTextBox control to drag a selection of a text and drop it into a tree view control. It works except after the drag and drop operation the RichTextBox scrolls to the...
3
by: Rob | last post by:
I've searched for info on how to drag and drop a group of strings (or any other object) from one control to another. Looked through articles by Dino Esposito, checked the Forms books by Sells and...
1
by: timnels | last post by:
I have created a muti-select treeview control. Problem is I am now trying to implement drag/drop in the application that uses it. It seems the mouse down and mouse move events fire before the...
2
by: bob | last post by:
Hi all, I have a treeview that has drag drop. Works well enough but... If you drag out of bounds of the treeview the nodrop icon comes on. Fair enough. But when I move back inside the treeview...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.