当前位置: 代码迷 >> ASP.NET >> asp.net2.0中treeview绑定数据库,100分 急该如何处理
  详细解决方案

asp.net2.0中treeview绑定数据库,100分 急该如何处理

热度:6800   发布时间:2013-02-25 00:00:00.0
asp.net2.0中treeview绑定数据库,100分 急!!!!
数据库:
CategoryID         ParentID       名称                         层次

AE5931B0-BE45-4942-9D04-64A6901015DC 4B7C1DF5-D667-4533-AEF5-BA17EFDBD9B0 客戶服務處 00010001000100010013
FC7FEC56-A47B-43BE-854A-DBFF4420190C AE5931B0-BE45-4942-9D04-64A6901015DC 客服一部 000100010001000100130001
99156740-9756-4846-A43E-B5DC5B0394BB FC7FEC56-A47B-43BE-854A-DBFF4420190C 原廠作業課 0001000100010001001300010001
D1E4E03D-02B9-4B96-B927-BC0BA4B11111 FC7FEC56-A47B-43BE-854A-DBFF4420190C 退貨中心 0001000100010001001300010002
2D6F0030-8682-4EF9-B0B6-5DC8ACB23DC1 FC7FEC56-A47B-43BE-854A-DBFF4420190C 專案課 0001000100010001001300010003
F0053403-AA37-49FB-BED9-7340EC74346C FC7FEC56-A47B-43BE-854A-DBFF4420190C 維修收件課 0001000100010001001300010004
27CFCCEE-10E3-4684-8C5D-A530F6C92A94 FC7FEC56-A47B-43BE-854A-DBFF4420190C 維修備品課 0001000100010001001300010005
1A3C8766-2FF7-4B98-9F14-29CAF3ED69D4 AE5931B0-BE45-4942-9D04-64A6901015DC 客服二部 000100010001000100130002
76814578-7B84-4599-88CA-C2357AE3A3BD 1A3C8766-2FF7-4B98-9F14-29CAF3ED69D4 數位週邊課 0001000100010001001300020001
5FC60D8B-E9F4-4625-BA5D-9D5A54846635 1A3C8766-2FF7-4B98-9F14-29CAF3ED69D4 顯示器課 0001000100010001001300020002
B91E63D8-B183-4861-B48C-A8038D00EC66 1A3C8766-2FF7-4B98-9F14-29CAF3ED69D4 通訊課 0001000100010001001300020003
930221A4-32C3-4FE6-B5CA-D7672A766267 1A3C8766-2FF7-4B98-9F14-29CAF3ED69D4 光華服務站 0001000100010001001300020004
E4924CE5-D380-49AB-B439-10C5CBCA6D31 AE5931B0-BE45-4942-9D04-64A6901015DC 客服三部 000100010001000100130003
64C8475A-2EDC-4ED7-8347-83D213E5A9D0 E4924CE5-D380-49AB-B439-10C5CBCA6D31 伺服器課 0001000100010001001300030001
4E58AF8A-F119-4028-A223-9110FE1AD817 E4924CE5-D380-49AB-B439-10C5CBCA6D31 網路課 0001000100010001001300030002
824761DE-065F-4C76-8326-A28CE77ADC27 E4924CE5-D380-49AB-B439-10C5CBCA6D31 系統課 0001000100010001001300030003
727D3FD9-CE7D-43B0-BEAE-614EEA4496E9 AE5931B0-BE45-4942-9D04-64A6901015DC 客服四部 000100010001000100130004
19F4B8E5-8E43-4A5F-981D-68243013F16A 727D3FD9-CE7D-43B0-BEAE-614EEA4496E9 桃竹客服課 0001000100010001001300040001
DC8F9AF8-42A1-4820-9B3E-885C2247B223 727D3FD9-CE7D-43B0-BEAE-614EEA4496E9 維修收件課 0001000100010001001300040002
699493C4-BA3C-47AD-B4EA-0BA7903E33EA 727D3FD9-CE7D-43B0-BEAE-614EEA4496E9 數位週邊課 0001000100010001001300040003
D7163846-A836-4E9E-A4A5-9D402737AA72 727D3FD9-CE7D-43B0-BEAE-614EEA4496E9 系統整合課 0001000100010001001300040004
F5C4F2F3-77F4-4327-A8D6-A78000087889 AE5931B0-BE45-4942-9D04-64A6901015DC 客服五部 000100010001000100130005
E582CA2F-B01C-4136-8F91-4E1B7DFC60A5 F5C4F2F3-77F4-4327-A8D6-A78000087889 台南客服課 0001000100010001001300050001
D69FAEF8-9CEC-4408-9145-77FB9D866032 F5C4F2F3-77F4-4327-A8D6-A78000087889 高雄客服課 0001000100010001001300050002


按照层次在treeview中显示,,注意id   和   parentid都是uniqueidentifier类型
最好是用递归的方法
真的很急啊,谢谢大家了


------解决方案--------------------------------------------------------
private void addNode(string ParentID, TreeNode pNode)
{
DataSet ds = (DataSet)this.ViewState[ "ds "];
DataView dvTree = new DataView(ds.Tables[0]);
dvTree.RowFilter = "ParentID = ' " + ParentID + " ' ";
foreach (DataRowView drv in dvTree)
{
TreeNode node = new TreeNode();
if (pNode == null)
{
node.Text = drv[ "NodeName "].ToString();
this.mytreeview.Nodes.Add(node);
node.Expanded = true;
// node.NavigateUrl = drv[ "URL "].ToString();
// node.Value = drv[ "NodeID "].ToString();
int n = Convert.ToInt32(drv[ "NodeID "].ToString());
  相关解决方案