The example in this article describes the method by which ASP.net implements DataList and repeater nested bindings. Share to everyone for your reference, specific as follows:
<%@ 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" Onitem Databound= "Monitortypelist_itemdatabound" repeatdirection= "horizontal" itemstyle-verticalalign= "Top" > < itemtemplate> <table class= "Conbox" width= "186" border= "0" cellpadding= "0" cellspacing= "1" style= "Margin-rig ht: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> </it
Emtemplate> </asp:Repeater> </table> </ItemTemplate> </asp:DataList> </form> &L
T;/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.is
Loginnonreturn (); 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 = = Li Stitemtype.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 mo
Nitor_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 ();
}
}
}
}
More interested in asp.net related content readers can view the site topics: "asp.net file Operation skills Summary", "ASP.net ajax Skills Summary" and "asp.net cache operation skills Summary."
I hope this article will help you to ASP.net program design.