在asp.net中使用数据库绑定css菜单 [英] Bind css Menu with database in asp.net

查看:60
本文介绍了在asp.net中使用数据库绑定css菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨frnds,



我需要将Css菜单与我们的数据库绑定在我们的应用程序中查看菜单..我差不多完成但需要你的帮助。以下是我的示例代码



Hi frnds,

I need to bind Css Menu with our database for viewing menu in our application.. I finished almost but need some help from you. Below is my sample Code

<br />
<div><br />
<div class = 'Column'><br />
  <a href=''></a><br />
  <a href=''></a><br />
</div><br />
<div class ='column'><br />
  <a href=''></a><br />
  <a href=''></a><br />
<div><br />
<div><br />




来自上面代码的
,列类div应拆分为拆分我们的下拉菜单。我尝试使用旗帜,但不会正确。我试图绑定 in while循环所以在while循环中



from the above code that column class div should split to split our dropdown menu. I tried using flag but wont get it correctly. i tried to bind the
in while loop so in while loop the

应该在绑定10行后显示应该关闭并再次绑定。
should display after binding 10 rows that should close and again should bind.

推荐答案

最简单的解决方法是 - 在aspx页面中放置一个LabelLabelMenu。在.cs页面中创建一个成员函数。

在该函数中编写代码来执行以下任务:



1.获取菜单来自数据库的数据并将它们绑定到数据集。

2.创建一个字符串类型变量,您可以在其中编写菜单的html部分。使用初始HTML对其进行初始化。 Say - string MyString =< div class ='mystyle'>;

3.编写foreach循环以获取数据集并使用字符串类型变量将html菜单与菜单名称和从数据库中提取的URL。

4.遍历数据集后,编写结束的HTML标记,将标记写入标签。

5.您的菜单是准备好了。



请看下面的例子。

The simplest solution to this is - put a Label say "LabelMenu" in aspx page. create a member function in .cs page.
Within that function write code to do the the following task:

1. Get your menu data from your database and bind them to a dataset.
2. Create a string type variable where you can write your html part of the menu. Initialize it with the intial HTML. Say - string MyString = "<div class='mystyle'>";
3. Write a foreach to loop to get thru the dataset and use the string type variable to integrate the html menu with menu name and URL fetched from database.
4. once the dataset is traversed, write the closing HTML tags, write the sting to the Label.
5. Your menu is ready.

Please see the below example.
private void fnPopulateMenu()
{
    DataSet DsMenu = new DataSet();
    string TblMenu = "<table class='MenuCss'><tr>";
    //Fetch and Bind data to DataSet
    .....
    foreach (string Drow in DsMenu.Tables[0].Rows)
    {
         TblMenu += "<td><a href='"+Drow["MenuLink"] +"'>"+Drow["MenuName"]+"</a></td>";
    }
    TblMenu = "</tr></table>";
    LabelMenu.Text = TblMenu;
}


这篇关于在asp.net中使用数据库绑定css菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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