April 12th, 2011 09:34 PM
#1
MVC 3 - Generating Html for forum
Code:
<html>
<head>
<title> Forum Index</title>
</head>
<body>
<table class="common-tbl cat" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th><h4><a href="">Category</a></h4></th>
</tr>
</thead>
<tbody>
<tr>
<td><h4><a href="" title=""></a>Forum Title</h4>Description</td>
<td><a href="" title="">RE: Last Post</a><br />
by <a href="" title="">Member Name</a><br />DateTime</td>
</tr>
</tbody>
</table>
</body>
</html>
I have made the above code which will suffice for my main page of the simple forum I am making. I need to customize this code based on the information I have in the database. Say for example I have 3 forums with the parent the category which would look like this:
Code:
<html>
<head>
<title> Forum Index</title>
</head>
<body>
<table class="common-tbl cat" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th><h4><a href="">Category</a></h4></th>
</tr>
</thead>
<tbody>
<tr>
<td><h4><a href="" title=""></a>Forum Title</h4>Description</td>
<td><a href="" title="">RE: Last Post</a><br />
by <a href="" title="">Member Name</a><br />DateTime</td>
</tr>
<tr>
<td><h4><a href="" title=""></a>Forum Title</h4>Description</td>
<td><a href="" title="">RE: Last Post</a><br />
by <a href="" title="">Member Name</a><br />DateTime</td>
</tr>
<tr>
<td><h4><a href="" title=""></a>Forum Title</h4>Description</td>
<td><a href="" title="">RE: Last Post</a><br />
by <a href="" title="">Member Name</a><br />DateTime</td>
</tr>
</tbody>
</table>
</body>
</html>
So say I query my database table and count the 3 forums that are linked to that category. How would I make this dynamic? And ideas are appreciated. I have a few of my own which I will attempt now.
April 13th, 2011 12:16 AM
#2
Re: MVC 3 - Generating Html for forum
There are several methods, however the one I prefer is using a DataRepeater..
so your code here
Code:
<table class="common-tbl cat" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th><h4><a href="">Category</a></h4></th>
</tr>
</thead>
<tbody>
<tr>
<td><h4><a href="" title=""></a>Forum Title</h4>Description</td>
<td><a href="" title="">RE: Last Post</a><br />
by <a href="" title="">Member Name</a><br />DateTime</td>
</tr>
<tr>
<td><h4><a href="" title=""></a>Forum Title</h4>Description</td>
<td><a href="" title="">RE: Last Post</a><br />
by <a href="" title="">Member Name</a><br />DateTime</td>
</tr>
<tr>
<td><h4><a href="" title=""></a>Forum Title</h4>Description</td>
<td><a href="" title="">RE: Last Post</a><br />
by <a href="" title="">Member Name</a><br />DateTime</td>
</tr>
</tbody>
</table>
Is repeated for each of the forums/ catalogs/ topics...
Replace that piece with the repeater like this
Code:
<asp:Repeater ID="RepForum" runat="server" OnItemCommand="RepForum_ItemCommand">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td><asp:HyperLink ID="Lnkforum" runat="server" NavigateUrl='<%#DataBinder.Eval(Container, "dataItem.url")%>'><%#DataBinder.Eval(Container, "dataItem.subject")%></asp:HyperLink>
</td>
<td><%#DataBinder.Eval(Container, "dataItem.Last_post")%> <asp:LinkButton ID="BtnUser" runat="server" Visible='<%#DataBinder.Eval(Container, "dataItem.VlastPost")%>'
CommandArgument='<%#DataBinder.Eval(Container, "dataItem.Last_Post_Author_ID")%>' CommandName="BtnUser">By <%#DataBinder.Eval(Container, "dataItem.Last_post_Author")%><br />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
You can then query the info from a database and attach the Data Object to the Repeater and it will Dynamically Add more rows as there is more data..
Articles VB6 : Break the 2G limit - Animation 1 , 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips : VB6 Hex Edit , IP Chat , Copy Prot. , Crop, Zoom : .NET IP Chat (V4) , Adv. ContextMenus , click Hotspot , Scroll Controls
Find me in ASP.NET. , VB6. , VB.NET , Writing Articles , My Genealogy , Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
April 13th, 2011 09:43 AM
#3
Re: MVC 3 - Generating Html for forum
Thanks for the response Ill try this out
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks