<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LeftMenu.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <mce:style type="text/css" ><!-- .ExpandCollapsePanelCss { vertical-align:baseline; cursor:hand; } A { font-size: 9pt; color: #006699; text-decoration: none; } --></mce:style><style type="text/css" mce_bogus="1"> .ExpandCollapsePanelCss { vertical-align:baseline; cursor:hand; } A { font-size: 9pt; color: #006699; text-decoration: none; } </style> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" Width="111px" OnRowDataBound="GridView1_RowDataBound" DataKeyNames="ID"> <RowStyle BackColor="White" ForeColor="#003399" /> <Columns> <asp:TemplateField > <ItemTemplate> <asp:Panel ID="Panel1" runat="server" Height="18px" Width="140px" BackImageUrl="~/IMAGE/manageshow.gif"> <%#Eval("Name") %></asp:Panel> <asp:Panel ID="Panel2" runat="server" Height="43px" Width="138px"> <asp:DataList ID="DataList1" runat="server"> <ItemTemplate> <a href="#" mce_href="#"><%#Eval("Username")%></a> </ItemTemplate> </asp:DataList></asp:Panel> <cc1:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" runat="server" CollapseControlID="Panel1" ExpandControlID="Panel1" TargetControlID="Panel2"> </cc1:CollapsiblePanelExtender> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#99CCCC" ForeColor="#003399" /> <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" /> <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" /> <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" /> </asp:GridView> </ContentTemplate> </asp:UpdatePanel> </form> </body> </html> using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Microsoft.Practices.EnterpriseLibrary.Common; using Microsoft.Practices.EnterpriseLibrary.Data; using System.Data.Common; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { GVDataBind(); } } private void GVDataBind() { Database db = DatabaseFactory.CreateDatabase(); DbCommand dcmd = db.GetSqlStringCommand("select * from dbo.[Group] where UserID=0"); DataSet ds = db.ExecuteDataSet(dcmd); this.GridView1.DataSource=ds.Tables[0]; this.GridView1.DataBind(); } private void DLDataBind(DataList dl,int GID) { Database db = DatabaseFactory.CreateDatabase(); string sql = "SELECT [User].*,[GroupUser].GroupID FROM [GroupUser] INNER JOIN [User] ON [User].ID=[GroupUser].UserID WHERE GroupID="+GID+""; DbCommand dcmd = db.GetSqlStringCommand(sql); DataSet ds = db.ExecuteDataSet(dcmd); dl.DataSource = ds.Tables[0]; dl.DataBind(); } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { DataList dlUser = (DataList)e.Row.FindControl("DataList1"); if (dlUser != null) { ///绑定数据 DLDataBind(dlUser, Int32.Parse(this.GridView1.DataKeys[e.Row.RowIndex].Value.ToString())); } } }