您的位置:首页 > 编程语言 > ASP

Devexpress ASP.NET中ASPxTreeList节点的拖动

2014-06-06 11:11 651 查看
估计很少有人知道Dev在ASP.NET中也能拖动节点。这个功能在我们需要对同一棵树的节点的位置进行调整的时候能用到。

前台树代码:

<dx:ASPxTreeList Width="400" ID="trlcustom" ClientInstanceName="trlcustom" ClientIDMode="Static" runat="server" AutoGenerateColumns="False"
KeyFieldName="DeptID" ParentFieldName="Parent" OnProcessDragNode="trlcustom_ProcessDragNode" OnInit="trlcustom_Init">
<Columns>
<dx:TreeListTextColumn FieldName="DeptName" VisibleIndex="0">
</dx:TreeListTextColumn>
<dx:TreeListTextColumn FieldName="Parent" VisibleIndex="1">
</dx:TreeListTextColumn>
</Columns>
<SettingsSelection AllowSelectAll="True" Enabled="True" Recursive="True" />
<Settings VerticalScrollBarMode="Visible" ScrollableHeight="300" />
<SettingsBehavior AutoExpandAllNodes="true" AllowDragDrop="true" AllowFocusedNode="true" />
<SettingsEditing AllowNodeDragDrop="true" />
</dx:ASPxTreeList>
后台代码:
/// <summary>
/// 绑定数据
/// </summary>
private void BindTreeList()
{
string sql = "select * from T_Dept";
dbclass.sql = sql;
DataSet dv = new DataSet();
dv = dbclass.Executeds();//只是查询填充
trlcustom.DataSource = dv;
trlcustom.DataBind();
}

/// <summary>
/// 树的init方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void trlcustom_Init(object sender, EventArgs e)
{
BindTreeList();
}

/// <summary>
/// 节点的拖动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void trlcustom_ProcessDragNode(object sender, DevExpress.Web.ASPxTreeList.TreeListNodeDragEventArgs e)
{
int dragDeptID = Convert.ToInt32(e.Node["DeptID"].ToString());
int dragDeptIDParent = Convert.ToInt32(e.Node["Parent"].ToString());
int dropDeptID = Convert.ToInt32(e.NewParentNode["DeptID"].ToString());
dbclass.sql = "update T_Dept set Parent= " + dropDeptID.ToString() + " where DeptID= " + dragDeptID.ToString();
if (!dbclass.executesql())
{
e.Handled = true;
return;
}
else
{
e.Handled = true;
BindTreeList();
}
}

效果如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息