drpdownlist中的层次结构 [英] Hierarchy in drpdownlist

查看:80
本文介绍了drpdownlist中的层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,
我正在使用一个具有下拉列表的应用程序,该列表显示层次结构中的数据,这意味着如果A作为B的父级,则下拉列表将显示这样的数据
A
-B-
--C--
D
我已使用此查询

Hello Friends,
I am working on a application that has a dropdownlist,which displays data in a hierarchy,means if A as the parent of B then dropdown will show data like this
A
-B-
--C--
D
I have used this query

With hierarchy (CatID, ParentCatID,CategoryName, depth, [path])
               As (

                   Select CatID, ParentCatID, CategoryName, 1 As depth,
                       Cast(Null as varChar(max)) As [path]
                   From Category
                   Where CatID = ParentCatID

                   Union All

                   Select child.CatID, child.ParentCatID, child.CategoryName,
                       parent.depth + 1 As depth,
                       IsNull(
                           Cast(parent.CatID As varChar(max)),
                           Cast(parent.CatID As varChar(max))
                       ) As [path]
                   From Category As child
                   Inner Join hierarchy As parent
                       On child.ParentCatID = parent.CatID
                   Where child.CatID != parent.ParentCatID)

               Select *
               From hierarchy
               Order By [depth] Asc;



在aspx.cs文件中,我使用了此



and in aspx.cs file i have used this

while (rs.Read())
           {

               string CatId = rs.GetGuid(0).ToString();//It shows error here
               int depth = rs.GetInt32(3);
               string text = rs.GetString(2);
               string parentId = rs.GetGuid(1).ToString();//It shows error here
               string padding = String.Concat(Enumerable.Repeat("- ", 2 * depth));


               if (CatId == parentId)
               {
                   ddlParentCatId.Items.Add(new ListItem(padding + text, CatId));
               }
               else
               {
                   int index = ddlParentCatId.Items.IndexOf(ddlParentCatId.Items.FindByValue(rs.GetString(4).ToString().ToLower()));

                   // Fix the location where the item is inserted.
                   index = index + 1;

                   ddlParentCatId.Items.Insert(index, new ListItem(padding + text, CatId));

               }


但我收到指定的强制转换错误,请帮助.


But i am getting an error of specified cast is invalid,kindly help.

推荐答案

请参阅我对问题的评论.目前尚不清楚您要使用哪个UI. (是的,我可以猜测,但是请不要告诉我必须这样做.)

但是,很明显,您正在尝试实现一些此控件不自然的功能.为了表示分层数据,使用TreeView.此类控件的确切类型取决于您要使用的UI,但是您可以在文档中轻松找到它.

—SA
Please see my comment to the question. It is not clear what UI do you want to use. (Yes, I can guess, but please don''t tell me I have to.)

Nevertheless, it''s apparent that you are trying to implement some features which are unnatural to this control. For presentation of hierarchical data, TreeView is used. Exact type of such control depends on UI you would use, but you can easily find it in documentation.

—SA


这篇关于drpdownlist中的层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆