2008年04月17日 星期四

Asp.Net Repeater控件嵌套查询

    我想实现的功能是现实一频道下的所有栏目下的前8篇文章。
html代码如下:
<asp:Repeater ID="repChannel" runat="server" >
                <HeaderTemplate>
   <div class="leftList">
                </HeaderTemplate>
                <ItemTemplate>
                                <asp:Repeater ID="repCategory" runat="server" DataSource='<%# GetCategoryArticle(Eval("ID").ToString()) %>'>
                <HeaderTemplate>
                <div class="blank20"></div>
                <ul>
                </HeaderTemplate>
                <ItemTemplate>
                <li>
           <h5>[<a href='ShowCategory.aspx?CategoryID=<%# DataBinder.Eval(Container.DataItem, "CategoryID")%>'><%# DataBinder.Eval(Container.DataItem, "CategoryID")%></a>] <a href='ShowArticle.aspx?CategoryID=<%# DataBinder.Eval(Container.DataItem, "CategoryID")%>&ArticleID=<%# DataBinder.Eval(Container.DataItem, "Article.ID")%>'><%# DataBinder.Eval(Container.DataItem, "Article.Title")%></a></h5>
           <h6><%# DataBinder.Eval(Container.DataItem, "PubDate")%></h6>
          </li>
                </ItemTemplate>
                <FooterTemplate></ul></FooterTemplate>
                </asp:Repeater>
                </ItemTemplate>
                <FooterTemplate>
                </div>
                </FooterTemplate>
                </asp:Repeater>
cs代码如下:
    protected OleDbDataReader GetCategoryArticle(string cid)
    {
        string StrConn = ConfigurationManager.ConnectionStrings["jcbConnectionString"].ConnectionString;
        string strSql = "select top 8 * from CCListView where CategoryID=" + cid + " order by Article.ID desc";
        OleDbConnection objConn = new OleDbConnection(StrConn);
        OleDbCommand objCmd = new OleDbCommand(strSql, objConn);
        objConn.Open();
        return objCmd.ExecuteReader(CommandBehavior.CloseConnection);
    }
CCListView视图如下:

执行结果:
DataBinding:“System.Data.Common.DbDataRecord”不包含名为“Article”的属性。

难道不可以这样吗??