首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎么读取数据表数据到菜单

2012-07-25 
如何读取数据表数据到菜单数据库表M_mesIDMenu1Menu2URL1PC123测试20120628082911.pdf2PC酸辣白菜20120628

如何读取数据表数据到菜单
数据库表M_mes
IDMenu1Menu2URL

1PC123测试20120628082911.pdf
2PC酸辣白菜20120628682715.pdf
3PC土豆20120628082718.pdf
4NC豆角20120628082761.pdf
5NC茄子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.DataSource = dv;      Repeater2.DataBind();    }  }</script><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server">  <title></title></head><body>  <form id="form1" runat="server">  <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">    <ItemTemplate>      <h2>        <%#Eval("Menu1")%></h2>      <div>        <asp:Repeater ID="Repeater2" runat="server">          <ItemTemplate>            <a href="<%#Eval("URL") %>">              <%#Eval("Menu2")%></a>          </ItemTemplate>        </asp:Repeater>      </div>    </ItemTemplate>  </asp:Repeater>  </form></body></html> 

热点排行