开始的时候在网上看了一些帖子,采用了OnItemDataBind();的方法 但是在内层的label控件上Text的数据不能绑定 出现的错误是找不到控件
后来用Relations方法
在内层的DataList  的DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>'
错误是CS0246: The type or namespace name 'DataRowView' could not be found (are you missing a using directive or an assembly reference?)但是我已经用了: using System.Data;为什么呢?请各位大虾解决下?

解决方案 »

  1.   

    表结构是(就一个表):
    id  parentid Board_Style_Name
    1       0        1111
    2       1        2222
    3       1        3333
    <%@ Page Language="C#" Debug="true"  Src="Behind_Code/index2.cs"   Inherits="Behind_index2.list2"%>
    <div align="center">
     <ASP:DataList id="MyDataList"  Width="100%"   RepeatColumns="1"  runat="server" >                                
     <ItemTemplate>
     <asp:label ID="Board_ID"  Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "ID")%>'   runat="server"></asp:label>
    <TABLE class=tableBorder1 cellSpacing=1 cellPadding=0 align=center>
      <TBODY>
      <TR>
                  <TH id=TableTitleLink align=left colSpan=2 height=25>&nbsp; <IMG src="images/nofollow.gif" width="15" height="15" border=0>
                    <%# DataBinder.Eval(Container.DataItem, "Board_Style_Name")%>
                  </TH>
      </TR>    
      <TR>
        <TD class=tablebody1 align=middle width="100%">
        <ASP:DataList id="MyDataList_Child"  Width="100%" DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>'   RepeatColumns="1"  runat="server">                                
          <ItemTemplate>
          <TABLE cellSpacing=0 cellPadding=0 width="100%">
            <TBODY>
            <TR>
               <TD class=tablebody1 align=middle width=46><img src="images/forum_nonews.gif"  width="24" height="24"> 
               </TD>
              <TD width=1 bgColor=#d66565>
              <TD class=tablebody1 vAlign=top width=*>
                <TABLE cellSpacing=0 cellPadding=2 width="100%" border=0>
                  <TBODY>
                  <TR>
                    <TD class=tablebody1 width=*><%# Container.ItemIndex+1%>
     <a href="Board_List.aspx?Board_ID=<%# DataBinder.Eval(Container.DataItem, "[\"ID\"]")%>"><FONT color=#000066>『<%# DataBinder.Eval(Container.DataItem, "[\"Board_Style_Name\"]")%>』</FONT></a>                   
                    </TD>
                    <TD class=tablebody1 align=middle width=40 rowSpan=2></TD>
                    <TD class=tablebody1 width=200 rowSpan=2>
     
     <asp:label ID="Title"   runat="server"></asp:label> 
      <BR> <asp:label ID="Author"   runat="server"></asp:label>
                     
                      <BR> <asp:label ID="Createtime"   runat="server"></asp:label>
      </TD></TR>
                  <TR>
                    <TD width=*> <FONT face=Arial><IMG src="images/Forum_readme.gif" width="10" height="10"align=middle> 
                          <%# DataBinder.Eval(Container.DataItem, "[\"Board_Style_Content\"]")%>
                      </FONT>
    </TD>
                 </TR>
                  <TR>
                    <TD class=tablebody2 width=* height=20>
    版主:   
                      &nbsp;</TD>
                    <TD class=tablebody2 align=middle width=40>&nbsp;</TD>
                    <TD class=tablebody2 vAlign=center width=200>                  
        </TD>
      </TR>
      </TBODY>
      </TABLE>
      </TD></TR>
      </TBODY>
      </TABLE>   
      </ItemTemplate>
              </ASP:DataList>
      </TD></TR>
     
      </TBODY>
        </TABLE><BR>   
       </ItemTemplate>
     </ASP:DataList>  
    </div>后台cs:string sql_child="select * from Board_Style where parentid in (select id from Board_Style where parentid=0)";
                  //Response.Write(sql_child);
                  //Response.End();
                    string sql_parent="select * from Board_Style  where parentid=0";
                    SqlDataAdapter mc= new SqlDataAdapter(sql_parent, myConnection);
            DataSet ds = new DataSet();
                    mc.Fill(ds,"board_info");                //DataRowView dv=new DataRowView(ds.Tables["Board_info"]);
                     SqlDataAdapter mc2= new SqlDataAdapter(sql_child, myConnection);
                     mc2.Fill(ds,"board_child_info");
                    ds.Relations.Add("myrelation",ds.Tables["board_info"].Columns["id"],ds.Tables["board_child_info"].Columns["parentid"]);
                    MyDataList.DataSource=ds.Tables["board_info"].DefaultView;
        MyDataList.DataBind();
      

  2.   

    aspx文件
    <%@ Import namespace="System.Data"%>
      

  3.   

    <ASP:DataList id="MyDataList_Child"  Width="100%" DataSource='<%# ((System.Data.DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>'   RepeatColumns="1"  runat="server">
      

  4.   

    呵呵
    现在问题得到了解决
    to:Eddie005(♂) 暴赱 『零零伍』 (︶︵︶) 
    我还是不大明白 我在cs文件中已经引用了using System.Data;
    为什么在前台还要加上呢》?现在给分了
      

  5.   

    因为它们就是2个文件,没什么特别的理由,如果要在aspx文件嵌入代码,养成把命名空间写全的习惯就好了