使用for循环在C#中显示数据库中的子项 [英] display child item from database in C# using for loops

查看:92
本文介绍了使用for循环在C#中显示数据库中的子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net菜单控件.

我不能向父项添加多个子菜单项.我能够得到
来自数据库,但无法在父菜单中显示.

我正在使用for循环代码

I am using asp.net menu control.

i am not able to add more than 1 child menu item to parent item. i am able to get
from database but can''t able display in parent menu.

i am using for loop code

推荐答案

foreach (DataRow parentItem in ds.Tables["Categories"].Rows)
  {
    MenuItem categoryItem = new MenuItem((string)parentItem["CategoryName"]);
    menu.Items.Add(categoryItem);

    foreach (DataRow childItem in parentItem.GetChildRows("Children"))
    {
      MenuItem childrenItem = new MenuItem((string)childItem["ProductName"]);
      categoryItem.ChildItems.Add(childrenItem);
    }
  }



请参考并检查您的循环



Refer this and check your loop


这篇关于使用for循环在C#中显示数据库中的子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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