How to create a table like VBF? (RESOLVED)
I have a table, Feedback.
I would like to display this data like VBF displays it's threads...In a grid thing.
I am sick of seeing code, but having no idea what to do with it, or where to place it in my code?
Can anyone help me?
I crash course of style sheets would be good.
Woof
Re: How to create a table like VBF?
Quote:
Originally posted by Wokawidget
I have a table, Feedback.
I would like to display this data like VBF displays it's threads...In a grid thing.
I am sick of seeing code, but having no idea what to do with it, or where to place it in my code?
Can anyone help me?
I crash course of style sheets would be good.
Woof
Woka, you could either use DataGrid or DataRepeater control. DataRepeater is more flexible if you wish to construck output with embeded tables.
It is simple to use.
First get your data into a DataSet and set the datasource property of the DataRepeater to dataset. Assuming you placed a Repeater Control called rpPost in the form. The following would go in the Page Load.
Code:
rpPost.DataSource=ds;
rpPost.DataMember="Post";
rpPost.DataBind();
Now the HTML for the page. You need to define three sections :
1. Header (e.g the table header, Here we open table)
2. Item Template (any code here gets looped, so in effect this is a loop)
3. Footer (any footer text, here we close the table)
Here is an example i stripped down from my ASP.Net forum
Hope this helps.
VB Code:
<BODY>
<center>
<h1 align="center"><% Response.Write(Thread_Title);%></h1>
<form id="thread" method="post" runat="server">
<asp:repeater id="rpPost" runat="server">
<HeaderTemplate>
<table bgcolor="LightBlue" width="90%" cellpadding="5" cellspacing="1">
<tr>
<td class="tableborder">Author</td>
<td class="tableborder"><b><% Response.Write (Thread_Title); %></b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="white">
<td width="20%" valign="top">
<b>
<%
string s;
s="<a href='GetUser.aspx?UserId=" + ds.Tables["Post"].Rows[i]["UserId"].ToString() + "'>" + ds.Tables["Post"].Rows[i]["Username"].ToString() + "</a>";
Response.Write (s);
%>
<br>
</b>
</td>
<td bgcolor="White">
<b>
<%# DataBinder.Eval(Container.DataItem, "PostTitle") %>
</b>
</td>
</tr>
<tr>
<td class="tableborder"><%# DataBinder.Eval(Container.DataItem, "Time_Created") %></td>
<td class="tableborder" align="right">
<table border="0">
<tr>
<td align="right"><a href='DeletePost.aspx?PostId=<%# DataBinder.Eval(Container.DataItem, "PostId") %>'>Delete</a></td>
<td align="right"><a href='reply.aspx?ThreadId=<%# DataBinder.Eval(Container.DataItem, "ThreadId")%>&PostId=<%# DataBinder.Eval(Container.DataItem, "PostId")%>'>Quote</a></td>
</tr>
</table>
</td>
</tr>
<%
i++;
%>
</ItemTemplate>
<FooterTemplate>
<tr>
<td class="tableborder" colspan="2" align="right">
<%
string lnk;
lnk="JavaScript:window.location='reply.aspx?ThreadId=" + threadid + "';" ;
%>
<input type="button" value="Reply" class="bttn" onclick="<% Response.Write(lnk);%>">
</td>
</tr>
</table>
</FooterTemplate>
</asp:repeater>
</center>
</FORM>
</BODY>