[WebForm]DataList里面如果再有一个DataList,两个数据源都是通过DAL层传出来的,现在不知道子DataList的DataBind()方法如何调用。
- C# code
using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using BLL;namespace TestWeb{ public partial class _Default : System.Web.UI.Page { private BLL.Bll bll = new Bll(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataBindQuestionDataList(); } } /// <summary> /// 绑定问题list控件 /// </summary> private void DataBindQuestionDataList() { this.DataList1.DataSource = bll.SearchQuestion(); this.DataList1.DataBind(); } public DataSet BindReply(Guid id) { return bll.SearchReply(id); } protected void dlReply_Load(object sender, EventArgs e) { } }}
页面代码
- HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestWeb._Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>无标题页</title></head><body> <form id="form1" runat="server"> <table border="0" width="100%" cellpadding="1" cellspacing="1"> <tr> <td> <label>问题主旨:</label> <asp:Label ID="labSubject" runat="server"></asp:Label> </td> </tr> <tr> <td><asp:DataList ID="DataList1" runat="server" > <ItemTemplate> <table border="0" cellpadding="1"> <tr> <td style="width:60px"> <asp:Label ID="labTitle" runat="server" Text="问题:"></asp:Label> </td> <td style="width:340px"> <asp:Label ID="labQuestion" runat="server" Text='<%# Bind("Content") %>'></asp:Label> </td> <td style="width: 60px"> </td> </tr> <tr> <td> <asp:DataList ID="dlReply" runat="server" DataSource='<%# BindReply((Guid)DataBinder.Eval(Container,"DataItem.CvsCmtID")) %>' OnLoad="dlReply_Load"> <ItemTemplate> <table border="0" > <tr> <td> <label>回覆:</label> </td> <td> <asp:Label ID="labReplyContent" runat="server" Text='<%# Bind("ReplyContent") %>' ></asp:Label> </td> <td> </td> </tr> </table> </ItemTemplate> </asp:DataList> </td> </tr> </table> </ItemTemplate> </asp:DataList> </td> </tr> <tr> <td> <label>通知记录:</label> </td> </tr> </table> </form></body></html>
[解决办法]
现绑定内嵌的那个,再绑定外层的那个
[解决办法]
先绑定外面的,再循环绑定里面的
或者
在itemdataband方法里面再依次绑定
[解决办法]
- C# code
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { DataList chindDl = (DataList)e.Item.FindControl("dlReply"); chindDl.DataSource = DataSource; chindDl.DataBind(); }
[解决办法]
外部绑定后,用ItemDataBound处理
实际上就类似repeater嵌套的绑定,找个repeater的来看看就可以了。
[解决办法]
编写一个函数,返回需要的html代码就可以了.