0

ユーザーフォーラムタイプのページを開発しようとしています。メインフォーラムのトピックがバインドされているデータリストがあります。その働き。今、特定のトピック(データリスト内の特定の行)のすぐ下に返信または提案を表示する必要があります。このようになります

データリスト

トピック 1

返信 1

返信 2

返信 3

トピック 2

返信 1

返信 2

返信 3

このような 。

トピックをデータリストにバインドしました。トピックのテーブル名は alltopics です。トピックへの返信は、tblreply という名前の別のテーブルに保存されます。トピックを datalist にバインドしました。しかし、他の部分を行う方法がわかりません。誰でも私を助けてくれますか

これは私がデータリストに使用したコードです

       Sub binddata5()
                    Dim mycommand As New SqlCommand("SELECT * from alltopics", con)

        con.Open()
        topics.DataSource = mycommand.ExecuteReader
        topics.DataBind()
        con.Close()

データリストの設計

         <asp:DataList ID="topics" runat="server" DataKeyField="id" 
              RepeatColumns="1">
                 <ItemTemplate>
                 <div>&nbsp&nbsp<strong><asp:Label
                      ID="detail" runat="server" Text='<%#Container.DataItem("topicdetails")%>'></asp:Label></strong>&nbsp&nbsp on &nbsp&nbsp<asp:Label ID="date" runat="server" Text='<%#Container.DataItem("ondate")%>'></asp:Label></td></tr>
                    </div>

                          </ItemTemplate>
                 </asp:DataList>
4

1 に答える 1

0

HTML MARK UP

<div>
    <asp:DataList ID="DataList1" runat="server" DataKeyField="bill_id" 
        DataSourceID="SqlDataSource1" OnItemDataBound="loaditems">
        <ItemTemplate>
            bill_id:
            <asp:Label ID="bill_idLabel" runat="server" Text='<%# Eval("bill_id") %>' />
            <br />
            bill_date:
            <asp:Label ID="bill_dateLabel" runat="server" Text='<%# Eval("bill_date") %>' />
            <br />
            bill_del_date:
            <asp:Label ID="bill_del_dateLabel" runat="server" 
                Text='<%# Eval("bill_del_date") %>' />
            <br />
            bill_pat_id:
            <asp:Label ID="bill_pat_idLabel" runat="server" 
                Text='<%# Eval("bill_pat_id") %>' />
            <br />
            <asp:DataList ID="DataList2" runat="server" DataKeyField="test_id">
                <ItemTemplate>
                    test_id:
                    <asp:Label ID="test_idLabel" runat="server" Text='<%# Eval("test_id") %>' />
                    <br />
                    <br />
                </ItemTemplate>
            </asp:DataList>
            <br />
        </ItemTemplate>
    </asp:DataList>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Diagnosticsql %>" 
        SelectCommand="SELECT * FROM [BILL]"></asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Diagnosticsql %>"             
        SelectCommand="SELECT * FROM [TEST] WHERE ([test_bill_id] like @test_bill_id)">
        <SelectParameters>
            <asp:Parameter Name="test_bill_id" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
</div>  

Code behind

Protected Sub loaditems(ByVal sender As Object, ByVal e As DataListItemEventArgs) Handles DataList1.ItemDataBound
    If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
        Dim billidlabel As Label = CType(e.Item.FindControl("bill_idLabel"), Label)
        Dim servicelist As DataList = CType(e.Item.FindControl("DataList2"), DataList)
        Me.SqlDataSource2.SelectParameters("test_bill_id").DefaultValue = billidlabel.Text
        servicelist.DataSourceID = SqlDataSource2.ID
    End If
End Sub
于 2012-05-06T17:46:45.230 に答える