Treeview - strange behavior on Server 2003

G

Guest

Hi,

I have the following problem. I have a project that uses the Treeview
control. The code supports drag-drop functionality for moving nodes between
different levels and for changing their order within a level. On Windows 2000
Server everything works fine. When I put it on the 2003 Server, everything
worked exactly the same except for changing the order of nodes within a level.

If this were an error in code, I'd expect it to not work in both cases. If
something were wrong with the placement of my /webctrl_client/1_0 folder, I'd
expect problems with other parts of Treeview functionality, which is not the
case. Does anybody know what is going on?
 
G

Guest

There are several functions. I'll post them in separate threads for brevity.
Here's the JavaScript function from the treeview.htc file:

function ml_ondrop()
{
//reset border
this.style.border = "";

var start_id = 0;
var end_id = 0;

if( ( window.event.type == "drop" ) && (
window.event.dataTransfer.getData( "Text" ) ) )
{
start_id = window.event.dataTransfer.getData( "Text" );
window.event.dataTransfer.clearData();

var end_node = this.parentElement.treenode;
if( end_node )
{
end_id = end_node.getAttribute( "NodeData" );
}

if( ( start_id > 0 ) && ( end_id != 0 ) )
{
if( start_id != end_id )
{
var s_action = "move";
var confirm_text = "Confirm the move.";
if( prop_shiftKeyPressed )
{
s_action = "sort";
confirm_text = "Confirm to rearrange.";
}

if( confirm( confirm_text ) )
{
var s_action = "move";
if( prop_shiftKeyPressed )
s_action = "sort";
window.document.location.href = window.document.location.pathname
+ "?editmode=true&action=" + s_action + "&source=" + start_id + "&target=" +
end_id;
}
}
}
else
{
alert( "An error occured!" );
}
}
}
 
G

Guest

The method reorderTreeItems is called from this bit of code in page_load:

if( !Page.IsPostBack )
{
resetTree.Attributes["onclick"] = @"return confirm('Jeste li sigurni?');";
if( action == "move" )
moveTreeItems();

if( action == "sort" )
reorderTreeItems();

getTreeItems();
}


void reorderTreeItems()
{
CPTreeView menu = new CPTreeView();
if( menu.IsReOrderValid( source, target ) )
{
try
{
menu.ReOrderItems( source, target );
Response.Redirect( Request.Path + "?editmode=true", true );
}
catch( Exception ex )
{
Trace.Warn( this.ToString(), ex.Message, ex );
infoLabel.Text = "An error occurred while changing the order of
pages.<br>" + ex.Message;
}
}
else
{
infoLabel.Text = "Incorrect parameters while changing the order of
pages. Please try again.";
}
}
 
G

Guest

Finally, ReOrderItems and orderSiblingsOnSort:

public void ReOrderItems( int source, int target )
{
if( DSWork() )
{
try
{
orderSiblingsOnSort( source, target );
saveItems();
}
catch( Exception ex ) { throw ex; }
}
}

void orderSiblingsOnSort( int source, int target )
{
int parent = getParent( source );
int sourceOrder = (int) ( dsWork.Tables[0].Select( "[PageID] = " +
source.ToString() ) )[0]["Ordering"];
int targetOrder = (int) ( dsWork.Tables[0].Select( "[PageID] = " +
target.ToString() ) )[0]["Ordering"];

// choose a sibling
string condition = "";
if( ( source == parent ) || ( target == -1 ) )
condition = "[Parent] = PageID";
else
condition = "[Parent] <> [PageID] AND [Parent] = " + parent.ToString();

DataRow[] siblings = dsWork.Tables[0].Select( condition, "[Ordering]
ASC");
// change the order
foreach( DataRow r in siblings )
{
if( ( Convert.ToInt32( r["Ordering"] ) > targetOrder ) && (
Convert.ToInt32( r["PageID"] ) != source ) )
r[ "Ordering" ] = Convert.ToInt32( r["Ordering"] ) + 1;
}

// set new order for source item
( dsWork.Tables[0].Select( "[PageID] = " + source.ToString() )
)[0]["Ordering"] = targetOrder+1;

DataRow[] siblings2 = dsWork.Tables[0].Select( condition, "[Ordering]
ASC");
for( int i = 0; i<siblings2.Length; i++ )
siblings2[ "Ordering" ] = i + 1;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top