DataList and Repeater nested bindings

Source: Internet
Author: User

<%@ 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.