asp.net实现DataList与Repeater嵌套绑定的方法
本文实例讲述了asp.net实现DataList与Repeater嵌套绑定的方法。分享给大家供大家参考,具体如下:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="home.aspx.cs"Inherits="home"%>
<body>
<formid="form1"runat="server">
<asp:DataListID="monitorTypeList"runat="server"RepeatColumns="4"
onitemdatabound="monitorTypeList_ItemDataBound"RepeatDirection="Horizontal"ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<tableclass="conBox"width="186"border="0"cellpadding="0"cellspacing="1"style="margin-right:10px;">
<tr>
<th><ahref="<%#Eval("plugpath")%>"><%#Eval("monitor_type_name")%></a></th>
</tr>
<asp:RepeaterID="monitorConfigList"runat="server">
<ItemTemplate>
<tr>
<td><ahref="<%#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
usingSystem;
usingSystem.Collections;
usingSystem.Configuration;
usingSystem.Data;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.HtmlControls;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Xml.Linq;
publicpartialclasshome:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
myCheck.IsLoginNonReturn();
if(!IsPostBack)
{
Bind_monitorTypeList();
}
}
protectedvoidBind_monitorTypeList()
{
stringsql="selectmonitor_type_id,monitor_type_namefrommonitor_type";
DbConnconn=newDbConn();
DataSetds=conn.DataSet(sql,"monitor_type");
monitorTypeList.DataSource=ds.Tables[0];
monitorTypeList.DataBind();
ds.Dispose();
conn.Close();
}
protectedvoidmonitorTypeList_ItemDataBound(objectsender,DataListItemEventArgse)
{
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
stringmonitor_type_id=((DataRowView)e.Item.DataItem).Row["monitor_type_id"].ToString();
RepeatermonitorConfigList=(Repeater)e.Item.FindControl("monitorConfigList");
if(monitorConfigList!=null)
{
stringsql="selectmonitor_id,nonitor_name,plugpathfrommonitorwheremonitor_type_id="+monitor_type_id;
DbConnconn=newDbConn();
DataSetds=conn.DataSet(sql,"monitor");
monitorConfigList.DataSource=ds.Tables[0];
monitorConfigList.DataBind();
ds.Dispose();
conn.Close();
}
}
}
}
更多关于asp.net相关内容感兴趣的读者可查看本站专题:《asp.net文件操作技巧汇总》、《asp.netajax技巧总结专题》及《asp.net缓存操作技巧总结》。
希望本文所述对大家asp.net程序设计有所帮助。
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短