原創(chuàng)|其它|編輯:郝浩|2012-11-06 11:54:41.000|閱讀 1792 次
概述:本示例主要展示如何通過代碼方式添加新的節(jié)點。 在本示例中ASPxTreeList控件被綁定到SQL數據庫。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
本示例主要展示如何通過代碼方式添加新的節(jié)點。 在本示例中ASPxTreeList控件被綁定到SQL數據庫。
C#
using System.Data.SqlClient; protected void Button1_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(); conn.ConnectionString= "Data Source=(local);Initial Catalog=TestDb;Integrated Security=True"; conn.Open(); int id = GenerateId(); int parentId = 0; if (ASPxTreeList1.FocusedNode != null) parentId = (int)ASPxTreeList1.FocusedNode["ID"]; string textCmd = string.Format("INSERT INTO [Table1] ([ID], [ParentID], [Name]) VALUES ({0}, {1}, '{2}')", id, parentId, ASPxTextBox1.Text); SqlCommand cmd = new SqlCommand(textCmd, conn); cmd.ExecuteNonQuery(); conn.Close(); ASPxTreeList1.DataBind(); }
Asp
<dxwtl:ASPxTreeList ID="ASPxTreeList1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" KeyFieldName="ID" ParentFieldName="ParentID" Width="307px"> <Columns> <dxwtl:TreeListTextColumn FieldName="Name" VisibleIndex="0"> </dxwtl:TreeListTextColumn> <dxwtl:TreeListSpinEditColumn FieldName="ID" VisibleIndex="1" Visible="False"> <PropertiesSpinEdit DisplayFormatString="g" NumberFormat="Custom"> </PropertiesSpinEdit> </dxwtl:TreeListSpinEditColumn> <dxwtl:TreeListSpinEditColumn FieldName="ParentID" VisibleIndex="1" Visible="False"> <PropertiesSpinEdit DisplayFormatString="g" NumberFormat="Custom"> </PropertiesSpinEdit> </dxwtl:TreeListSpinEditColumn> </Columns> <SettingsBehavior AllowFocusedNode="True" /> </dxwtl:ASPxTreeList>
運行代碼,結果如下:
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網