DataList与Repeater嵌套绑定

<%@ 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();
}
}
}
}

转自:http://www.cnblogs.com/Fooo/archive/2009/06/14/1503234.html

时间: 2024-11-08 21:03:03

DataList与Repeater嵌套绑定的相关文章

Repeater嵌套绑定Repeater

<asp:Repeater runat="server" ID="rpList" OnItemDataBound="rpList_ItemDataBound"> <ItemTemplate> <div class="catItem"> <h2> <%#Eval("DataValue")%> </h2> <div class=&qu

关于Repeater嵌套绑定的问题

前台代码: <div id="firstpane" class="menu_list">                <asp:Repeater ID="rep1" runat="server" onitemdatabound="rep1_ItemDataBound">                    <ItemTemplate>                 

转:Repeater嵌套绑定Repeater以及内层调用外层数据

<table border="0" cellpadding="0" cellspacing="0" style="margin-bottom: 5px" width="100%"> <asp:Repeater runat="server" ID="rptypelist" OnItemDataBound="rptypelist_ItemDat

Repeater嵌套gridview

前台:<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="Repeater1_ItemDataBound">        <ItemTemplate>           id:<%#Eval("ID")%>           carid:

DataList和Repeater

DataList和Repeater是两个十分有用的控件,在新闻列表和图片展示的地方经常用到.在这里简单的把他们介绍一下. 1.DataList: 前端页面: <asp:DataList ID="PicList" runat="server" RepeatColumns="3" Width="90%" RepeatDirection="Horizontal">               <

项目--Repeater嵌套横向显示

前台代码: <style type="text/css"> .list { list-style-type: none; text-align:center; } .list li { float: left; width: 160px; } </style> <ul class="list"> <asp:Repeater runat="server" ID="rptType">

Gridview、DataList、Repeater获取行索引号

Gridview.DataList.Repeater如何获取行索引号?很多情况下都会用得到,下面贴出代码,注意行索引号是从0开始,不是从1开始,如果要从1开始,请在代码里面+1就行了. Gridview示例: <asp:GridView ID="GridView1" runat="server">         <Columns>         <asp:TemplateField>         <ItemTempl

Repeater控件三层嵌套-内层Repeater添加绑定事件

用Repeater三层嵌套,最外层Repeater可以生成自己的ItemCommand事件.但接下来中间层因为是嵌套了的,所以无法在属性窗口中生成自己的事件.如果手动敲入则无效. 解决办法是需要通过编码的方式来添加事件. protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { //假设在第一层里面嵌套了一个名叫Repeater2 的 var temp = e.Item.FindControl

repeater三级嵌套绑定

<asp:Repeater ID="rpt1" runat="server" onitemdatabound="rpt1_ItemDataBound">         <HeaderTemplate> <table width=400 cellpadding=0 cellspacing=0></HeaderTemplate>            <ItemTemplate><t