有2个表,  
category
[cat_id]
[cat_name]items
[id]
[cat_id]
{item_name]想以这种方式显示cat_name 1
item 1
item 2
item 3cat_name 2
item 1
item 2
item 3请问用datalist里面在嵌套一个datalist可以实现么??请用datalist的方法,我看到了datagrid的例子,但是我还是想用datalist来做, repeater的例子我也看了,不过没看懂,呵呵,请各位朋友用datalist的例子来说明,谢谢.

解决方案 »

  1.   

    if you don't understand the solution with repeaters, how can you understand the solution with datalists?http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q306154&ID=KB;EN-US;Q306154&
      

  2.   

    前台.aspx文件<%@ Import Namespace="System.Data" %>
    <asp:datalist id="Datalist1" runat="server" RepeatDirection="Horizontal" RepeatColumns="2" CellSpacing="0"
    CellPadding="0" BorderWidth="0" Width="420px">
    <itemtemplate>
    <table width="210px" cellspacing="0" border="0">
    <tr height="40">
    <td valign="bottom" class="xiao13h"><a href='TradeList.aspx?id=<%# DataBinder.Eval(Container.DataItem,"id")%>&max_min=max&type=<%=ids%>'>
    <b>
    <%# DataBinder.Eval(Container.DataItem,"d_class") %>
    </b></a>
    </td>
    </tr>
    </table>
    <table width="210px" border="0" CellPadding="0" CellSpacing="0">
    <tr>
    <td>
    <asp:DataList ID="Datalist2" BorderWidth="0" CellPadding="0" CellSpacing="0" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" Width="220" DataSource='<%# getrow((DataRowView)Container.DataItem,3)%>'>
    <itemtemplate>
    <table width="65px" border="0" CellPadding="0" CellSpacing="0">
    <tr>
    <td class="xiao12h"><div align="center"><a href='TradeList.aspx?id=<%# DataBinder.Eval(Container.DataItem, "[\"id\"]")%>&max_min=min&type=<%=ids%>'>
    <%# CutString(DataBinder.Eval(Container.DataItem, "[\"x_class\"]").ToString(),4)%>
    </a>
    </div>
    </td>
    </tr>
    </table>
    </itemtemplate>
    </asp:DataList>
    </td>
    </tr>
    </table>
    </itemtemplate>
    </asp:datalist>后台.cs文件private void Page_Load(object sender, System.EventArgs e)
    {
    string s1="select id,d_class,d_class_readme from goods_d_class";
    mydb.Datacokis(s1,"goods_d_class",1);
    string s2="select id,x_class,x_class_readme,f_id from goods_x_class";
    mydb.Datacokis(s2,"goods_x_class",1);
    mydb.ds.Relations.Add("myrelation",
    mydb.ds.Tables["goods_d_class"].Columns["id"],
    mydb.ds.Tables["goods_x_class"].Columns["f_id"]); Datalist1.DataSource = mydb.ds.Tables["goods_d_class"];
    Datalist1.DataBind();
    }
    public DataRow[] getrow(DataRowView drv,int num)
    {
    DataRow[] dr=drv.Row.GetChildRows("myrelation"); if(dr.Length>num)
    {
    DataRow[] drtemp=new DataRow[num];
    for(int i=0;i<num;i++)
    {
    drtemp[i]=dr[i];
    }
    return drtemp;
    }
    else
    return drv.Row.GetChildRows("myrelation");
    }
      

  3.   

    saucer(思归) 
    cheers mate, I did not look at that article carefully, just have a look of it, pretty easy to understand, now, I get it.