如何在嵌套数据Web控件中实现ItemDataBound

时间:2016-03-21 07:15:45

标签: c# asp.net

我发现这篇文章有一个我完全需要的教程。

https://msdn.microsoft.com/en-us/library/bb510145.aspx

但我不明白如何实现ItemDataBound事件以及这些代码是什么。有没有人知道如何理解和实现这些代码在ItemDataBound event.youtube链接或一些明确的例子......

使用以下代码为CategoryList Repeater ItemDataBound事件创建事件处理程序:

Protected Sub CategoryList_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) _
Handles CategoryList.ItemDataBound
If e.Item.ItemType = ListItemType.AlternatingItem _
    OrElse e.Item.ItemType = ListItemType.Item Then

    ' Reference the CategoriesRow object being bound to this RepeaterItem
    Dim category As Northwind.CategoriesRow = _
        CType(CType(e.Item.DataItem, System.Data.DataRowView).Row, _
            Northwind.CategoriesRow)

    ' Reference the ProductsByCategoryDataSource ObjectDataSource
    Dim ProductsByCategoryDataSource As ObjectDataSource = _
        CType(e.Item.FindControl("ProductsByCategoryDataSource"), _
            ObjectDataSource)

    ' Set the CategoryID Parameter value
    ProductsByCategoryDataSource.SelectParameters("CategoryID").DefaultValue = _
        category.CategoryID.ToString()
End If
End Sub

我想实现一个嵌套的转发器。这是我的数据库模型:

enter image description here

和我的转发器在这里。我想使用Object数据源将它们绑定到数据库。我需要在嵌套转发器中为每个巡视创建一个startdate列表。

<asp:ObjectDataSource ID="ODSTTitle" runat="server" SelectMethod="GetById" TypeName="ATourRep">
            <SelectParameters>
                <asp:QueryStringParameter DefaultValue="0" Name="Id" QueryStringField="CID" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetById" TypeName="ATourDateRep">
            <SelectParameters>
                <asp:Parameter Name="Id" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>

<div class="container" id="TourDetail">

            <asp:Repeater ID="RptTourDetail" runat="server" DataSourceID="ODSTTitle" ItemType="Tour" EnableViewState="false" OnItemDataBound="RptTourDetail_ItemDataBound">
                <HeaderTemplate>

                    <ul>
                </HeaderTemplate>
                <ItemTemplate>
                    <li>



                        <img src="<%# Item.TImgUrl %>" alt="Alternate Text" class="img-responsive" />
                        <div class="row">


                            <div class="col-md-3">
                                <%-- NestedRepeater --%>
                                <p>
                                    <%# Item.TourId %>

                                </p>
                                <asp:Repeater ItemType="TourDate" ID="RptTourNested" runat="server" EnableViewState="false" DataSourceID="ObjectDataSource1">
                                    <ItemTemplate>
                                        <h2>
                                            <%-- What Should I write Here to have a list of each TourDate --%>
                                       <%# Item.TourStartDate %>
                                             </h2>
                                    </ItemTemplate>
                                </asp:Repeater>
                            </div>


                            <div class="col-md-6">
                                <%-- This Column works correctly --%>
                                <h4>
                                    <%# Item.TName %>
                                </h4>
                                <p>
                                    <%# Item.TDes %>
                                </p>
                            </div>


                            <div class="col-md-3">c</div>
                        </div>

                    </li>

                </ItemTemplate>

                <FooterTemplate>
                    </ul>
                </FooterTemplate>
            </asp:Repeater>

        </div>

0 个答案:

没有答案