主要是想实现一个嵌套功能
aspx中的程序为: <asp:DataList ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound" CellPadding="4" ForeColor="#333333" >
        <ItemTemplate>
         <asp:LinkButton ID="Label1" runat="server" Text='<%# Eval("ly_zhuti") %>'></asp:LinkButton>
         <asp:Label ID="lblliuyanID" runat="server"  Visible="false" Text='<%# Eval("ly_id") %>'></asp:Label>
         <br />
         <asp:DataList ID="DataList2" runat="server" Height="58px" Width="228px">
               <ItemTemplate>
                  <asp:Label ID="Lable3"  runat="server" Text='<% Eval("huifu_neirong") %>'></asp:Label>
                  <asp:Label ID="Lable4" runat="server" Text='<% Eval("ly_id") %>'></asp:Label>
               </ItemTemplate>
            </asp:DataList>
        </ItemTemplate>
       </asp:DataList>
Datalist2嵌套在DataList1中,
后台程序:

 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataList dl = null;
                Label lblTypeID = null;
                if (e.Item.ItemType == ListItemType.Item)
                {
                    dl = (DataList)e.Item.FindControl("DataList2");
                 }

运行到上面最后一句(dl = (DataList)e.Item.FindControl("DataList2");),会发现dl是已经被创建了,但Datalist2却始终显示在上下文中没有。而且程序运行后,只能显示DataList1的数据,不能显示DataList2中的数据。
请教各位高人!

解决方案 »

  1.   

    这2句在程序里写了
      protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
       {
           String connString = "Data Source=WORKGROU-RIEBHA;Initial Catalog=jiaoliu;User ID=webuser;Password=USSTjwcwebinfo2005";
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataList dl_List1 = null;
                Label Lbl_liuyanID = null;
                if (e.Item.ItemType == ListItemType.Item)
                {
                    dl_List1 = (DataList)e.Item.FindControl("DataList2");
                    
                    Lbl_liuyanID = (Label)e.Item.FindControl("lblliuyanID");
                
                String str_liuyanID = Lbl_liuyanID.Text.ToString();
                if (str_liuyanID.Trim()=="" )
                {
                    str_liuyanID="1";
                }
                String str_findhuifu_neirong = "select * from jwjl_liuyan_huifu ";
                str_findhuifu_neirong = str_findhuifu_neirong + " where ly_id=" + str_liuyanID;
                SqlConnection Conn_jiaoliu = new SqlConnection(connString);
                Conn_jiaoliu.Open();
                SqlDataAdapter Da_huifu = new SqlDataAdapter(str_findhuifu_neirong,Conn_jiaoliu);
                DataSet ds_huifu = new DataSet();
                Da_huifu.Fill(ds_huifu,"jwjl_liuyan_huifu");
                Conn_jiaoliu.Close();
                dl_List1.DataSource = ds_huifu.Tables["jwjl_liuyan_huifu"];
                dl_List1.DataBind();            }
            }
        }
      

  2.   

    呵呵~ 谢谢~~http://community.csdn.net/Expert/topic/4878/4878352.xml?temp=1.491725E-03