473,388 Members | 1,215 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,388 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 1160
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.