如何读取数据表数据到菜单
数据库表M_mes
IDMenu1Menu2URL
1PC123测试20120628082911.pdf
2PC酸辣白菜20120628682715.pdf
3PC土豆20120628082718.pdf
4NC豆角20120628082761.pdf
5NC茄子20120628032711.pdf
如何生成如下样式
<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>
<%@ 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>