UltraWebTree的递归绑定和节点拖动

1.html代码
< HTML >
< HEAD >
< title > TreeView </ title >
< meta content ="MicrosoftVisualStudio.NET7.1" name ="GENERATOR" >
< meta content ="C#" name ="CODE_LANGUAGE" >
< meta content ="JavaScript" name ="vs_defaultClientScript" >
< meta content ="http://schemas.microsoft.com/intellisense/ie5" name ="vs_targetSchema" >
< SCRIPT type ="text/javascript" >
functionUltraWebTree1_DragStart(oTree,oNode,oDataTransfer,oEvent)
{
//debugger;
oDataTransfer.dataTransfer.setData("Text",oNode.getText());
oDataTransfer.dataTransfer.effectAllowed
="move";
}


functionUltraWebTree1_Drop(oTree,oNode,oDataTransfer,oEvent)
{
//debugger;
if(oNode.getParent()!=null)
{
alert(
"Pleasemakesurethattheformismovedtoacaseandtryagain.");
returnfalse;
}

varsourceNode=oDataTransfer.sourceObject;
if(sourceNode.getParent()==null)
{
alert(
"Pleasemakesurethattheformismovedtoacaseandtryagain.");
returnfalse;
}


oNode.addChild(oDataTransfer.dataTransfer.getData(
"Text"));
oNode.setExpanded(
true);


if(sourceNode)
{
sourceNode.remove();

}

returnfalse;
}


</ SCRIPT >
</ HEAD >
< body >
< form id ="Form1" method ="post" runat ="server" >
< TABLE id ="Table1" height ="100%" cellSpacing ="0" cellPadding ="0" width ="100%" border ="0" >

< TR vAlign ="top" height ="100%" >
< TD colSpan ="2" >< ignav:ultrawebtree id ="UltraWebTree1" runat ="server" AllowDrop ="True" AllowDrag ="True" BorderStyle ="Groove"
BackColor
="#E0E0E0" BrowserTarget ="Auto" Cursor ="hand" WebTreeTarget ="HierarchicalTree" AutoPostBack ="False"
Editable
="False" Height ="100%" Width ="100%" BorderWidth ="3px" >
< SelectedNodeStyle ForeColor ="White" BackColor ="DarkBlue" ></ SelectedNodeStyle >
< Padding Top ="5px" ></ Padding >
< Levels >
< ignav:Level Index ="0" ></ ignav:Level >
< ignav:Level Index ="1" ></ ignav:Level >
< ignav:Level Index ="2" ></ ignav:Level >
</ Levels >
< Styles >
<ignav:StyleCssClass="DefaultItemClass"></ignav:Style>
<ignav:StyleCursor="Hand"Font-Underline="True"Font-Names="Arial"ForeColor="#FF8000"BackColor="PaleGoldenrod"
CssClass="HoverClass"></ignav:Style>
<ignav:StyleForeColor="White"BackColor="Tan"CssClass="HiliteClass"></ignav:Style>
</ Styles >
< ClientSideEvents AfterNodeSelectionChange ="AfterNodeSelChange" DragStart ="UltraWebTree1_DragStart"
Drop
="UltraWebTree1_Drop" ></ ClientSideEvents >
</ ignav:ultrawebtree ></ TD >
</ TR >
</ TABLE >
</ form >
</ body >
</ HTML >

2.cs代码
// usingInfragistics.WebUI.UltraWebNavigator;
public class TreeView:System.Web.UI.Page
{
protectedInfragistics.WebUI.UltraWebNavigator.UltraWebTreeUltraWebTree1;

privatevoidPage_Load(objectsender,System.EventArgse)
{
if(!Page.IsPostBack)
{
UltraWebTree1.Nodes.Clear();
BindTree(UltraWebTree1.Nodes,ds.Tables[
0],"0");
}

}

privatevoidBindTree(Infragistics.WebUI.UltraWebNavigator.NodesNds,DataTabledt,stringid)
{
DataViewdv
=newDataView(dt);
dv.RowFilter
="parentid='"+id.ToString()+"'";
Nodenode;

foreach(DataRowViewdrvindv)
{
node
=newNode();
node.Tag
=drv["id"].ToString();
node.Text
=drv["name"].ToString();
node.Expanded
=true;
Nds.Add(node);
BindTree(node.Nodes,dt,drv[
"id"].ToString());
}

}



WebFormDesignergeneratedcode#regionWebFormDesignergeneratedcode
overrideprotectedvoidOnInit(EventArgse)
{
//
//CODEGEN:ThiscallisrequiredbytheASP.NETWebFormDesigner.
//
InitializeComponent();
base.OnInit(e);
}


/**////<summary>
///RequiredmethodforDesignersupport-donotmodify
///thecontentsofthismethodwiththecodeeditor.
///</summary>

privatevoidInitializeComponent()
{
this.Load+=newSystem.EventHandler(this.Page_Load);

}

#endregion


GetData#regionGetData
privateDataTableGetData()
{
DataTabledt;
dt
=newDataTable();

dt.Columns.Add(
"id");
dt.Columns.Add(
"parentid");
dt.Columns.Add(
"name");

DataRowdr;
dr
=dt.NewRow();
dr[
"id"]="1";
dr[
"parentid"]="0";
dr[
"name"]="a";
dt.Rows.Add(dr);

dr
=dt.NewRow();
dr[
"id"]="2";
dr[
"parentid"]="1";
dr[
"name"]="b";
dt.Rows.Add(dr);

dr
=dt.NewRow();
dr[
"id"]="3";
dr[
"parentid"]="1";
dr[
"name"]="c";
dt.Rows.Add(dr);

dr
=dt.NewRow();
dr[
"id"]="4";
dr[
"parentid"]="2";
dr[
"name"]="d";
dt.Rows.Add(dr);

dr
=dt.NewRow();
dr[
"id"]="5";
dr[
"parentid"]="2";
dr[
"name"]="e";
dt.Rows.Add(dr);

dr
=dt.NewRow();
dr[
"id"]="6";
dr[
"parentid"]="3";
dr[
"name"]="f";
dt.Rows.Add(dr);
returndt;

}


}

你可能感兴趣的:(tree)