在下拉列表中显示层次结构 [英] show hierarchy in Dropdownlist

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

问题描述

我正在使用表类别,并且我有三列CatID,CatName,ParentcatId,

在ParentCatId中,我必须在Hierarchy中显示catId列值.

I am using the table category and in that I have Three Column CatID,CatName,ParentcatId,

In ParentCatId I have to show the catId column value in Hierarchy

推荐答案

使用标准HTML选择列表,有两种显示层次结构的方法:

1.如果无法选择根节点,则可以使用optgroup元素.不幸的是,ASP.NET DropDownList不支持optgroups.

2.如果可以选择根节点,请使用空格缩进子节点

最简单的方法是将结果集中的深度值用作:
With standard HTML select lists there are two ways to display hierarchy:

1. If root nodes are not selectable, you can use optgroup elements. Unfortunately, ASP.NET DropDownList does not support optgroups.

2. If root nodes are selectable, use whitespace to indent child nodes

Easiest way is to use the depth value in your resultset as:
DropDownList ddl = new DropDownList();
while (rs.Read())
{
    string id = rs.GetGuid(0).ToString();
    int depth = rs.GetInt32(3);
    string text = rs.GetString(2);
    string padding = String.Concat(Enumerable.Repeat(" ", 4 * depth));
    ddl.Items.Add(new ListItem(padding + text, id));
}


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

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