haku
haku

Reputation: 4505

Assign separate link to each repeater item in ASP .net

I was trying to develop a forum website (trying to mimic some of its features) and I am using Entity framework to get my data. I have to use repeater as my instructor asked me to do so.

I would be having something like this using repeater that gets data for "Forum Category" and "Sub-category" from 2 separate database tables:

Now, I would like, when clicked on those sub-category list to be directed to the page of their own using query string and that is what I am not being able to figure out at this time. When I assign a link to those sub-lists, since they are automatically generated all of them point to the page that I initially assign. I was wondering if there was someway to dynamically assign links for this scenario. I was thinking of using ENUM, but again how do I run a for loop there.

The code I have for the repeater is below:

<asp:Repeater ID="categoryRepeater" runat="server" OnItemDataBound="RepeaterDataBinding">
            <ItemTemplate>
              <asp:Label ID="categoryLabel" Text='<%#Eval("CatName") %>' runat ="server" 
                  style="font-weight:bold;font-size:large" />
                <br />
                <asp:Repeater ID="forumRepeater" runat="server">
                    <ItemTemplate>
                        <a href="DesktopForum1.aspx?ForumID=<%#Eval("ForumID") %>"><%#Eval("ForumName")%></a><br/>
                       <%-- right up there. Instead of hardcoding "DesktopForum1.aspx?ForumID=" which makes all the links
                           to point to that page, I am trying to achieve a way to assign links to specific pages for each sub-list...
                           --%>
                    </ItemTemplate>
                </asp:Repeater>
            </ItemTemplate>
        </asp:Repeater>

I did try searching the forum, but could not come across with a problem that resembled my situation.

Upvotes: 1

Views: 1119

Answers (2)

Netricity
Netricity

Reputation: 2738

If you're able to get the sub-list page URL with the query that populates forumRepeater, this should work:

<a href='<%#Eval("ForumUrl")%>'><%#Eval("ForumName")%></a><br/>

Upvotes: 1

Andrei
Andrei

Reputation: 44600

Would you like to put some acnchor for each item?

It will look like that:

<a name="someAnchor"></a>

and Link will be as follows: www.mywebsite.com/blog/posts#someAnchor

For more details: http://www.echoecho.com/htmllinks08.htm

If it is still not good, you need to handle and process querystring values with Javascript

Upvotes: 0

Related Questions