0
votes

I have a repeater set up in Visual Studio to try and grab the latest 3 blog titles from the database and show the associated image along with the title, intro and a link.

However the parent div of each blog needs to have a different ID.

Currently I have the following code but it's not working because I've since found out you can't have an itemtemplate followed by an alternating item template followed by another item template.

I there any workaround to this?

    <asp:Repeater runat="server" ID="repeaterNews1" DataSourceID="SQLDataNews1">
        <ItemTemplate>
            <div id="blog1">
                <div class="col-xs-12">
                    <asp:Image runat="server" ID="Image1" ImageUrl='<%# Eval("NewsStoryImage") %>'/>
                    <div class="blogContent">
                        <div class="container">
                            <h2>Our Blog</h2>
                            <p><asp:Label runat="server" ID="Label1" Text='<%# Eval("PageTitle") %>'></asp:Label></p>
                            <p><asp:Label runat="server" ID="Label2" Text='<%# Eval("Content1") %>'></asp:Label></p>
                            <a href='<%# Eval("PageUrl") %>' alt="">Read More</a>
                        </div>
                    </div>
                </div>
            </div>
        </ItemTemplate>
        <AlternatingItemTemplate>
            <div id="blog2">
                <div class="col-xs-12">
                    <asp:Image runat="server" ID="Image2" ImageUrl='<%# Eval("NewsStoryImage") %>'/>
                    <div class="blogContent">
                        <div class="container">
                            <h2>Our Blog</h2>
                            <p><asp:Label runat="server" ID="Label1" Text='<%# Eval("PageTitle") %>'></asp:Label></p>
                            <p><asp:Label runat="server" ID="Label2" Text='<%# Eval("Content1") %>'></asp:Label></p>
                            <a href='<%# Eval("PageUrl") %>' alt="">Read More</a>
                        </div>
                    </div>
                </div>
            </div>
        </AlternatingItemTemplate>
        <ItemTemplate>
            <div id="blog3">
                <div class="col-xs-12">
                    <asp:Image runat="server" ID="Image3" ImageUrl='<%# Eval("NewsStoryImage") %>'/>
                    <div class="blogContent">
                        <div class="container">
                            <h2>Our Blog</h2>
                            <p><asp:Label runat="server" ID="Label1" Text='<%# Eval("PageTitle") %>'></asp:Label></p>
                            <p><asp:Label runat="server" ID="Label2" Text='<%# Eval("Content1") %>'></asp:Label></p>
                            <a href='<%# Eval("PageUrl") %>' alt="">Read More</a>
                        </div>
                    </div>
                </div>
            </div>
        </ItemTemplate>
    </asp:Repeater>
1
Why would you need third item template? the id will be different of each Image you are going to populate.Just code
Oh wow, you're right. How did I not think of that lolFazy

1 Answers

1
votes

No, you cannot create a third template.

What you can do is make sure the ID's are still unique by using Container.DataItemIndex

<ItemTemplate>
    <div id="blog<%# Container.DataItemIndex %>"></div>
</ItemTemplate>