求教:如果将多重分类绑定到一个DropDownList?

epjack 2004-12-08 08:32:28
库categories:
+-------+--------------+------------------+
| ID | categoryname | parentcategoryID |
+-------+--------------+------------------+
|1 | a | 0 |
+-------+--------------+------------------+
|2 | b | 1 |
+-------+--------------+------------------+
|3 | c | 0 |
+-------+--------------+------------------+
|4 | e | 2 |
+-------+--------------+------------------+
例表形式为:
<asp:ListItem Value="0">a</asp:ListItem>
<asp:ListItem Value="2">a>b</asp:ListItem>
<asp:ListItem Value="4">a>b>e</asp:ListItem>
<asp:ListItem Value="3">c</asp:ListItem>

...全文
110 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
epjack 2004-12-08
  • 打赏
  • 举报
回复
能不能详细点啊。我是笨蛋一个,太多东西还不大明白,谢谢。
stephenZL 2004-12-08
  • 打赏
  • 举报
回复
你可以创建一个DataTable,然后写一个递归函数按你的要求动态的生成DataRow,然后邦定到dropdownList上面就可邓撒
epjack 2004-12-08
  • 打赏
  • 举报
回复
happyfamily(NETstep) 没有认真看我的问题吧?
happyfamily 2004-12-08
  • 打赏
  • 举报
回复
用DataSet也可其他
dropdownList.DataTextField = "字段名";
dropdownList.DataValueField = "字段id";

dropdownList.DataSource = 数据源;
dropdownList.DataBind();

epjack 2004-12-08
  • 打赏
  • 举报
回复
能写个完整一点的例子子吗?如何绑定到DropDownList控件里?
Eddie005 2004-12-08
  • 打赏
  • 举报
回复
如果最大层次是有限的话可以一句sql搞定
select t1.id,t1.categoryname+t2.categoryname+t3.categoryname... from categories t1
left join categories t2 on t1.parentcategoryID=t2.id
left join categories t3 on t2.parentcategoryID=t3.id
...
kenMoxi 2004-12-08
  • 打赏
  • 举报
回复
select * from ategories order by id desc,parentcategoryID desc
epjack 2004-12-08
  • 打赏
  • 举报
回复
<asp:ListItem Value="1">a</asp:ListItem>
<asp:ListItem Value="2">a>b</asp:ListItem>
<asp:ListItem Value="4">a>b>e</asp:ListItem>
<asp:ListItem Value="3">c</asp:ListItem>

这个才对,parentcategoryID为0,则表示根分类。 建议用vb.net来写。谢谢

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧