UltraWebTree的递归绑定和节点拖动

本文介绍了一个使用UltraWebTree控件实现的TreeView示例,包括HTML和C#代码。示例展示了如何设置TreeView的样式、配置节点拖拽功能,并通过数据绑定动态生成树形结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.html代码
None.gif<HTML>
None.gif
<HEAD>
None.gif
<title>TreeView</title>
None.gif
<metacontent="MicrosoftVisualStudio.NET7.1"name="GENERATOR">
None.gif
<metacontent="C#"name="CODE_LANGUAGE">
None.gif
<metacontent="JavaScript"name="vs_defaultClientScript">
None.gif
<metacontent="http://schemas.microsoft.com/intellisense/ie5"name="vs_targetSchema">
ExpandedBlockStart.gifContractedBlock.gif
<SCRIPTtype="text/javascript">dot.gif
InBlock.gif
functionUltraWebTree1_DragStart(oTree,oNode,oDataTransfer,oEvent)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
//debugger;
InBlock.gif
oDataTransfer.dataTransfer.setData("Text",oNode.getText());
InBlock.gifoDataTransfer.dataTransfer.effectAllowed
="move";
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
functionUltraWebTree1_Drop(oTree,oNode,oDataTransfer,oEvent)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
//debugger;
InBlock.gif
if(oNode.getParent()!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifalert(
"Pleasemakesurethattheformismovedtoacaseandtryagain.");
InBlock.gif
returnfalse;
ExpandedSubBlockEnd.gif}

InBlock.gif
varsourceNode=oDataTransfer.sourceObject;
InBlock.gif
if(sourceNode.getParent()==null)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifalert(
"Pleasemakesurethattheformismovedtoacaseandtryagain.");
InBlock.gif
returnfalse;
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gifoNode.addChild(oDataTransfer.dataTransfer.getData(
"Text"));
InBlock.gifoNode.setExpanded(
true);
InBlock.gif
InBlock.gif
InBlock.gif
if(sourceNode)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifsourceNode.remove();
InBlock.gif
ExpandedSubBlockEnd.gif}

InBlock.gif
returnfalse;
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedBlockEnd.gif
</SCRIPT>
None.gif
</HEAD>
None.gif
<body>
None.gif
<formid="Form1"method="post"runat="server">
None.gif
<TABLEid="Table1"height="100%"cellSpacing="0"cellPadding="0"width="100%"border="0">
None.gif
None.gif
<TRvAlign="top"height="100%">
None.gif
<TDcolSpan="2"><ignav:ultrawebtreeid="UltraWebTree1"runat="server"AllowDrop="True"AllowDrag="True"BorderStyle="Groove"
None.gifBackColor
="#E0E0E0"BrowserTarget="Auto"Cursor="hand"WebTreeTarget="HierarchicalTree"AutoPostBack="False"
None.gifEditable
="False"Height="100%"Width="100%"BorderWidth="3px">
None.gif
<SelectedNodeStyleForeColor="White"BackColor="DarkBlue"></SelectedNodeStyle>
None.gif
<PaddingTop="5px"></Padding>
None.gif
<Levels>
None.gif
<ignav:LevelIndex="0"></ignav:Level>
None.gif
<ignav:LevelIndex="1"></ignav:Level>
None.gif
<ignav:LevelIndex="2"></ignav:Level>
None.gif
</Levels>
ExpandedBlockStart.gifContractedBlock.gif
<Styles>dot.gif
InBlock.gif<ignav:StyleCssClass="DefaultItemClass"></ignav:Style>
InBlock.gif<ignav:StyleCursor="Hand"Font-Underline="True"Font-Names="Arial"ForeColor="#FF8000"BackColor="PaleGoldenrod"
InBlock.gifCssClass="HoverClass"></ignav:Style>
InBlock.gif<ignav:StyleForeColor="White"BackColor="Tan"CssClass="HiliteClass"></ignav:Style>
ExpandedBlockEnd.gif
</Styles>
None.gif
<ClientSideEventsAfterNodeSelectionChange="AfterNodeSelChange"DragStart="UltraWebTree1_DragStart"
None.gifDrop
="UltraWebTree1_Drop"></ClientSideEvents>
None.gif
</ignav:ultrawebtree></TD>
None.gif
</TR>
None.gif
</TABLE>
None.gif
</form>
None.gif
</body>
None.gif
</HTML>

2.cs代码
None.gif//usingInfragistics.WebUI.UltraWebNavigator;
None.gif
publicclassTreeView:System.Web.UI.Page
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif
protectedInfragistics.WebUI.UltraWebNavigator.UltraWebTreeUltraWebTree1;
InBlock.gif
InBlock.gif
privatevoidPage_Load(objectsender,System.EventArgse)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
if(!Page.IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifUltraWebTree1.Nodes.Clear();
InBlock.gifBindTree(UltraWebTree1.Nodes,ds.Tables[
0],"0");
ExpandedSubBlockEnd.gif}

ExpandedSubBlockEnd.gif}

InBlock.gif
privatevoidBindTree(Infragistics.WebUI.UltraWebNavigator.NodesNds,DataTabledt,stringid)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifDataViewdv
=newDataView(dt);
InBlock.gifdv.RowFilter
="parentid='"+id.ToString()+"'";
InBlock.gifNodenode;
InBlock.gif
InBlock.gif
foreach(DataRowViewdrvindv)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifnode
=newNode();
InBlock.gifnode.Tag
=drv["id"].ToString();
InBlock.gifnode.Text
=drv["name"].ToString();
InBlock.gifnode.Expanded
=true;
InBlock.gifNds.Add(node);
InBlock.gifBindTree(node.Nodes,dt,drv[
"id"].ToString());
ExpandedSubBlockEnd.gif}

ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif
WebFormDesignergeneratedcode#regionWebFormDesignergeneratedcode
InBlock.gif
overrideprotectedvoidOnInit(EventArgse)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
//
InBlock.gif
//CODEGEN:ThiscallisrequiredbytheASP.NETWebFormDesigner.
InBlock.gif
//
InBlock.gif
InitializeComponent();
InBlock.gif
base.OnInit(e);
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**////<summary>
InBlock.gif
///RequiredmethodforDesignersupport-donotmodify
InBlock.gif
///thecontentsofthismethodwiththecodeeditor.
ExpandedSubBlockEnd.gif
///</summary>

InBlock.gifprivatevoidInitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
this.Load+=newSystem.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif}

ExpandedSubBlockEnd.gif
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif
GetData#regionGetData
InBlock.gif
privateDataTableGetData()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifDataTabledt;
InBlock.gifdt
=newDataTable();
InBlock.gif
InBlock.gifdt.Columns.Add(
"id");
InBlock.gifdt.Columns.Add(
"parentid");
InBlock.gifdt.Columns.Add(
"name");
InBlock.gif
InBlock.gifDataRowdr;
InBlock.gifdr
=dt.NewRow();
InBlock.gifdr[
"id"]="1";
InBlock.gifdr[
"parentid"]="0";
InBlock.gifdr[
"name"]="a";
InBlock.gifdt.Rows.Add(dr);
InBlock.gif
InBlock.gifdr
=dt.NewRow();
InBlock.gifdr[
"id"]="2";
InBlock.gifdr[
"parentid"]="1";
InBlock.gifdr[
"name"]="b";
InBlock.gifdt.Rows.Add(dr);
InBlock.gif
InBlock.gifdr
=dt.NewRow();
InBlock.gifdr[
"id"]="3";
InBlock.gifdr[
"parentid"]="1";
InBlock.gifdr[
"name"]="c";
InBlock.gifdt.Rows.Add(dr);
InBlock.gif
InBlock.gifdr
=dt.NewRow();
InBlock.gifdr[
"id"]="4";
InBlock.gifdr[
"parentid"]="2";
InBlock.gifdr[
"name"]="d";
InBlock.gifdt.Rows.Add(dr);
InBlock.gif
InBlock.gifdr
=dt.NewRow();
InBlock.gifdr[
"id"]="5";
InBlock.gifdr[
"parentid"]="2";
InBlock.gifdr[
"name"]="e";
InBlock.gifdt.Rows.Add(dr);
InBlock.gif
InBlock.gifdr
=dt.NewRow();
InBlock.gifdr[
"id"]="6";
InBlock.gifdr[
"parentid"]="3";
InBlock.gifdr[
"name"]="f";
InBlock.gifdt.Rows.Add(dr);
InBlock.gif
returndt;
InBlock.gif
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedBlockEnd.gif}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值