<%@ page language= "C #" autoeventwireup= "true" codefile= "Home.aspx.cs" inherits= "Home"%>
<body>
<form id= "Form1" runat= "Server" >
<asp:datalist id= "monitortypelist" runat= "Server" repeatcolumns= "4"
Onitemdatabound= "Monitortypelist_itemdatabound" repeatdirection= "horizontal" itemstyle-verticalalign= "Top" >
<ItemTemplate>
<table class= "Conbox" width= "186" border= "0" cellpadding= "0" cellspacing= "1" style= "margin-right:10px;" >
<tr>
<th><a href= "<% #Eval (" Plugpath ")%>" ><% #Eval ("Monitor_type_name")%></a></th>
</tr>
<asp:repeater id= "monitorconfiglist" runat= "Server" >
<ItemTemplate>
<tr>
<td><a href= "<% #Eval (" Plugpath ")%>?monitor_id=<% #Eval (" monitor_id ")%>" ><% #Eval (" Monitor_name ")%></a></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</ItemTemplate>
</asp:DataList>
</form>
</body>
Home.aspx.cs
Using System;
Using System.Collections;
Using System.Configuration;
Using System.Data;
Using System.Linq;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Xml.Linq;
public partial class Home:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
Mycheck.isloginnonreturn ();
if (! IsPostBack)
{
Bind_monitortypelist ();
}
}
protected void Bind_monitortypelist ()
{
String sql = "Select Monitor_type_id,monitor_type_name from Monitor_type";
Dbconn conn = new Dbconn ();
DataSet ds = conn. DataSet (SQL, "Monitor_type");
Monitortypelist.datasource = ds. Tables[0];
Monitortypelist.databind ();
Ds. Dispose ();
Conn. Close ();
}
protected void Monitortypelist_itemdatabound (object sender, DataListItemEventArgs e)
{
if (E.item.itemtype = = ListItemType.Item | | e.item.itemtype = = listitemtype.alternatingitem)
{
String monitor_type_id = ((DataRowView) e.item.dataitem). row["monitor_type_id"]. ToString ();
Repeater monitorconfiglist = (Repeater) e.item.findcontrol ("Monitorconfiglist");
if (monitorconfiglist! = null)
{
String sql = "Select Monitor_id,nonitor_name,plugpath from Monitor where monitor_type_id=" + monitor_type_id;
Dbconn conn = new Dbconn ();
DataSet ds = conn. DataSet (SQL, "Monitor");
Monitorconfiglist.datasource = ds. Tables[0];
Monitorconfiglist.databind ();
ds. Dispose ();
Conn. Close ();
}
}
}
}
Transferred from: http://www.cnblogs.com/Fooo/archive/2009/06/14/1503234.html
DataList and Repeater nested bindings