前台代码:
<asp:DataList ID="DataList1" runat="server" onitemdatabound="DataList1_ItemDataBound"> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "Page_Group_Name")%> <asp:Label ID="labId" runat="server" Visible="false" Text='<%#Eval("Id") %>'></asp:Label> <asp:DataList ID="DataList2" runat="server" RepeatColumns="1"> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "System_Page_Name")%> </ItemTemplate> </asp:DataList> </ItemTemplate> </asp:DataList>
后台代码:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Bind(); } } public void Bind() { BLL.System_Page_Group system_page_group = new BLL.System_Page_Group(); DataSet ds = system_page_group.GetList1("");
DataList1.DataSource = ds.Tables[0].DefaultView; DataList1.DataBind(); } protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { int index = e.Item.ItemIndex; if (e.Item.ItemType == ListItemType.Item) { DataList dl = (DataList)e.Item.FindControl("DataList2"); Label labId = (Label)e.Item.FindControl("labId"); string id = labId.Text; BLL.System_Page system_page = new BLL.System_Page(); DataSet ds = system_page.GetList(" System_Page_Group_Id='" + id + "'"); dl.DataSource = ds.Tables[0]; dl.DataBind(); } }
为什么不对啊?他只显示外面DataList的数据,不显示里面的。。。