<asp:DataList ID="Dlt_Class" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" BorderColor="White" EnableTheming="True" Height="422px" Width="736px">    <ItemTemplate>
        <table style="width: 242px; border-right: lime 3px double; border-top: lime 3px double; border-left: lime 3px double; border-bottom: lime 3px double;">
            <tr>
                <td style="width: 223px; font-weight: bold; font-size: 10pt;" align="center">
                    <a href="ClassType.aspx?id=<%# Eval("PKID") %>&twoid=<%# Eval("UPID") %>"><%# DataBinder.Eval(Container.DataItem, "ClassName")%></a>
                </td>
            </tr>
            <tr>
                <td style="width: 223px; height: 73px;">
    <asp:DataList id="childDataList" runat="server"  RepeatColumns="3" RepeatDirection="Horizontal" datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>'>  /////下面的无法绑定
     <HeaderTemplate>
     <table cellspacing="0" cellpadding="0" width="100%">
     <tr>
     <td>
     </HeaderTemplate>
      <itemtemplate>
          <a href="ClassType.aspx?id=<%# Eval("[\"PKID\"]") %>&twoid=<%# Eval("[\"UPID\"]") %>"><%# DataBinder.Eval(Container.DataItem, "[\"ClassName\"]")%></a>&nbsp;&nbsp;&nbsp;&nbsp;
      </itemtemplate>
      <FooterTemplate>
      </td>
      </tr>
      </table>     
      
      </FooterTemplate>
    </asp:DataList></td>
            </tr>
          
        </table>
    
    </ItemTemplate>
    <ItemStyle VerticalAlign="Top" />
      
        
</asp:DataList>
  页面只显示大类的名称 大类下面的子类都无法显示
后台代码
 
     public void Bind()
   {
    string strSQL,strSQL1, strSQL2;
            strSQL1 = "select * from t_sj_ClassInfo where UPID=0  ";
            strSQL2 = "select * from t_sj_ClassInfo where UPID<>0  ";
            strSQL = strSQL1 + ";" + strSQL2;
            DataSet ds = GetDataSet(strSQL);
            ds.Relations.Add("myrelation", ds.Tables[0].Columns["PKID"], ds.Tables[1].Columns["PKID"],false);
            Dlt_Class.DataSource = ds.Tables[0];
            Dlt_Class.DataBind();
  }public static DataSet GetDataSet(string sql)
        {
           
            SqlDataAdapter da = null;
            DataSet ds = new DataSet();
            int i = 1;
            string[] strSqls = sql.Split(';');
            foreach (string strSql in strSqls)
            {
                da = GetAdapter(strSql);
                da.Fill(ds, "table" + i.ToString());
                i++;
            }            return ds;
            
        }
        public static SqlDataAdapter GetAdapter(string sql)
        {
            SqlDataAdapter da = new SqlDataAdapter((SqlCommand)GetCommand(sql));
            return da;
        }
        public static IDbCommand GetCommand(string sql)
        {
            IDbCommand cmd = new SqlCommand(sql, (SqlConnection)GetConnection());
            return cmd;
        }
        public static IDbConnection GetConnection()
        {
            IDbConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["dbConnStr"]);
            return cnn;
        } 数据库如下
   PKID  ClassName  UPID  code
   1      水果        0    0001
   2      苹果       1     00010001
   3      香蕉       1     00010002
   4      家电        0    0002
   5      彩电        4    00020001期待各位的答复
  

解决方案 »

  1.   

       public void Bind()
       {
               string strSQL,strSQL1, strSQL2;
                strSQL1 = "select * from t_sj_ClassInfo where UPID=0  ";
                strSQL2 = "select * from t_sj_ClassInfo where UPID<>0  ";
                strSQL = strSQL1 + ";" + strSQL2;
                DataSet ds = GetDataSet(strSQL);
                Dlt_Class.DataSource = ds.Tables[0];
                Dlt_Class.DataBind();
                childDataList.DataSource=ds.Tables[1];
                childDataList.DataBind();
      }public static DataSet GetDataSet(string sql)
            {
                DataSet ds = new DataSet();
                SqlDataAdapter da = GetAdapter(strSql);
                da.Fill(ds);
                return ds;        
            }
      

  2.   


      嵌套在里面的  你能把childDataList直接拿出来绑定??  你试下你写的看能通过不?
      

  3.   

      子datalist有datasource