日期:2014-05-17  浏览次数:20429 次

如何读取数据表数据到菜单
数据库表M_mes
ID Menu1 Menu2 URL

1 PC 123测试 20120628082911.pdf
2 PC 酸辣白菜 20120628682715.pdf
3 PC 土豆 20120628082718.pdf
4 NC 豆角 20120628082761.pdf
5 NC 茄子 20120628032711.pdf

如何生成如下样式
HTML code

                        <h2>PC</h2>
                        <DIV>
                        <a href="20120628082911.pdf">123测试</a>
                        <a href="20120628682715.pdf">酸辣白菜</a>
                        <a href="20120628082718.pdf">土豆</a>
                        </DIV>

                        <h2>NC</h2>
                        <DIV>
                        <a href="20120628082761.pdf">豆角</a>
                        <a href="20120628032711.pdf">茄子</a>
                        </DIV>




------解决方案--------------------
外层Repeater用 select distinct Menu1 from tab 这个绑定撒
 
子Repeater 在外层绑定事件里面 取外层 Menu1 字段值 value 用 select id , menu2 from tab where menu1 = 'value ' 绑定


------解决方案--------------------
都给你例子了你都没去看
下面的代码直接拷贝粘贴成xx.aspx,直接浏览,总会吧
HTML code
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">  
  System.Data.DataTable dataTable1 = new System.Data.DataTable();
  protected void Page_Load(object sender, EventArgs e)
  {
    dataTable1.Columns.Add(new System.Data.DataColumn("Id", typeof(System.Int32)));
    dataTable1.Columns.Add(new System.Data.DataColumn("Menu1", typeof(System.String)));
    dataTable1.Columns.Add(new System.Data.DataColumn("Menu2", typeof(System.String)));
    dataTable1.Columns.Add(new System.Data.DataColumn("URL", typeof(System.String)));
    dataTable1.Rows.Add(new Object[] { 1, "PC", "123测试", "20120628082911.pdf" });
    dataTable1.Rows.Add(new Object[] { 2, "PC", "酸辣白菜", "20120628682715.pdf" });
    dataTable1.Rows.Add(new Object[] { 3, "PC", "土豆", "20120628082718.pdf" });
    dataTable1.Rows.Add(new Object[] { 4, "NC", "豆角", "20120628082761.pdf" });
    dataTable1.Rows.Add(new Object[] { 5, "NC", "茄子", "20120628032711.pdf" });

    System.Data.DataView dv = dataTable1.DefaultView;
    System.Data.DataTable dataTable2 = dv.ToTable(true, "Menu1");
    System.Data.DataTable dataTable3 = dataTable1.Clone();

    this.Repeater1.DataSource = dataTable1.DefaultView.ToTable(true, "Menu1");
    this.Repeater1.DataBind();
  }

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    if (e.Row.Cells[0].Text.Trim().Equals("合计"))
    {
      e.Row.Style.Add("color", "#d00");
    }
    else if (e.Row.Cells[0].Text.Trim().Equals("总合计"))
    {
      e.Row.Style.Add("color", "#00d");
      e.Row.Style.Add("background", "#f33");
    }
  }

  protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
  {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
      Repeater Repeater2 = e.Item.FindControl("Repeater2") as Repeater;
      String Menu1 = DataBinder.Eval(e.Item.DataItem, "Menu1").ToString();
      System.Data.DataView dv = dataTable1.DefaultView;
      dv.RowFilter = "Menu1='" + Menu1 + "'";
      Repeater2.Data