1

少し前にこの質問をしたのですが、返事がありませんでした。それ以来、他のことで忙しくしていましたが、今日戻ってきましたが、まだ解読できません。

私の元の質問: https://stackoverflow.com/questions/11868289/using-a-one-to-many-relationship-to-show-a-category-menu-using-asp-repeaters-vb

それ以来、この記事 http://www.codeproject.com/Articles/6140/A-quick-guide-to-using-nested-repeaters-inをたどろうとするときに、自分が間違っていることを確認しようとしています-ASP-NETとさまざまな Microsfot チュートリアル

データセットを埋める際にステップが抜けているか、何かを誤解していると思います...そして今朝、ぐるぐる回って過ごしたので、私は地獄のように混乱しています.

それは私を壁に追いやっています。

私はここまで来ました: (ちなみに、私は ASP.NET 2.0 と MySQL データベースを使用しています)

Sub getCategories() Handles Me.Load

    Dim DBConnection = ConfigurationManager.ConnectionStrings("dbConnNew").ConnectionString
    Dim connection As OdbcConnection = New OdbcConnection(DBConnection)
    Dim connect As New OdbcCommand("SELECT masterCat.name AS masterCat, masterCat.id as mcId, category.id as cId, category.name AS category, category.mapsTo as catMapsTo, subCat.mapsTo as subCatMapsTo, subCat.name AS subCat FROM masterCat INNER JOIN category ON masterCat.id = category.mapsTo INNER JOIN subCat ON category.id = subCat.mapsTo WHERE masterCat.id <> '9' ORDER BY masterCat.priority", connection)

    Dim DS As New DataSet()
    connection.Open()
    Dim read As OdbcDataReader = connect.ExecuteReader(CommandBehavior.CloseConnection)
    DS.Load(read, LoadOption.OverwriteChanges, "masterCat, category, subCat")

    'DS.Relations.Add("mCatid", DS.Tables("masterCat").Columns("mcId"), DS.Tables("category").Columns("cId")) << This Line Breaks

    connection.Close()

    masterCat.DataSource = DS
    masterCat.DataBind()

End Sub

Private Sub CategoryRepeater_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles masterCat.ItemDataBound
    Dim item As RepeaterItem = e.Item
    If (item.ItemType = ListItemType.Item) OrElse (item.ItemType = ListItemType.AlternatingItem) Then
        Dim catRpt = DirectCast(item.FindControl("catRepeater"), Repeater)
        Dim drv As DataRowView = DirectCast(item.DataItem, DataRowView)
        catRpt.DataSource = drv.CreateChildView("mcId")
        catRpt.DataBind()
    End If
End Sub

そしてマークアップ:

         <ul>
            <asp:Repeater ID="masterCat" runat="server">
                <ItemTemplate>
                    <li>
                        <%# Container.DataItem("masterCat")%>
                        <ul>                            
                            <asp:Repeater ID="catRepeater" runat="server">
                            <ItemTemplate>
                                <li>
                                <%# Container.DataItem("category")%>
                            </li>
                            </ItemTemplate>
                            </asp:Repeater>
                        </ul>
                    </li>
                </ItemTemplate>
            </asp:Repeater>
         </ul>

要約すると、マスター カテゴリ、カテゴリ、およびサブカテゴリのネストされたリピーターを作成しようとしています。上記のコードは 2 つのステップを実行しているだけです。

私のデータは、次のような 3 つのテーブルに配置されています。

masterCat

id    |    name    | priority (for sorting)

category

id    |    name    |    mapsTo (this is the ID of the masterCat to which this relates)

subCat

 id    |    name    | mapsTo (ID of the category to which this relates)

上記の SQL クエリは、次の列を含むデータ全体を正しく返します。

masterCat   - name of the master category
mcId        - ID of the master category
cId         - ID of a category
category    - name of a category
catMapsTo   - the ID of the masterCategory to which category relates
subCat       - subCategory name
subCatMapsTo - the ID of the category to which the subCategory relates

最終的に必要なのは、次のようなものです (この例では 2 レベルの深さです)。

  • マスターキャット
    • カテゴリー
    • カテゴリー
    • カテゴリー


  • マスターキャット
    • カテゴリー
    • カテゴリー
    • カテゴリー

  • マスターキャット
    • カテゴリー
    • カテゴリー
    • カテゴリー

        </li>
    

助けていただければ幸いです。

4

0 に答える 0