Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I best populate an HTML table in ASP.NET?
    text
    copied!<p>This is what I've got. It works. But, is there a simpler or better way?</p> <p>ASPX Page&hellip;</p> <pre><code>&lt;asp:Repeater ID="RepeaterBooks" runat="server"&gt; &lt;HeaderTemplate&gt; &lt;table class="report"&gt; &lt;tr&gt; &lt;th&gt;Published&lt;/th&gt; &lt;th&gt;Title&lt;/th&gt; &lt;th&gt;Author&lt;/th&gt; &lt;th&gt;Price&lt;/th&gt; &lt;/tr&gt; &lt;/HeaderTemplate&gt; &lt;ItemTemplate&gt; &lt;tr&gt; &lt;td&gt;&lt;asp:Literal ID="LiteralPublished" runat="server" /&gt;&lt;/td&gt; &lt;td&gt;&lt;asp:Literal ID="LiteralTitle" runat="server" /&gt;&lt;/td&gt; &lt;td&gt;&lt;asp:Literal ID="LiteralAuthor" runat="server" /&gt;&lt;/td&gt; &lt;td&gt;&lt;asp:Literal ID="LiteralPrice" runat="server" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/ItemTemplate&gt; &lt;FooterTemplate&gt; &lt;/table&gt; &lt;/FooterTemplate&gt; &lt;/asp:Repeater&gt; </code></pre> <p>ASPX.VB Code Behind&hellip;</p> <pre><code>Protected Sub Page_Load( ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim db As New BookstoreDataContext RepeaterBooks.DataSource = From b In db.Books _ Order By b.Published _ Select b RepeaterBooks.DataBind() End Sub Sub RepeaterBooks_ItemDataBound( ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles RepeaterBooks.ItemDataBound If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then Dim b As Book = DirectCast(e.Item.DataItem, Book) DirectCast(e.Item.FindControl("LiteralPublished"), Literal).Text = "&lt;nobr&gt;" + b.Published.ToShortDateString + "&lt;/nobr&gt;" DirectCast(e.Item.FindControl("LiteralTitle"), Literal).Text = "&lt;nobr&gt;" + TryNbsp(HttpContext.Current.Server.HtmlEncode(b.Title)) + "&lt;/nobr&gt;" DirectCast(e.Item.FindControl("LiteralAuthor"), Literal).Text = "&lt;nobr&gt;" + TryNbsp(HttpContext.Current.Server.HtmlEncode(b.Author)) + "&lt;/nobr&gt;" DirectCast(e.Item.FindControl("LiteralPrice"), Literal).Text = "&lt;nobr&gt;" + Format(b.Price, "c") + "&lt;/nobr&gt;" End If End Sub Function TryNbsp(ByVal s As String) As String If s = "" Then Return "&amp;nbsp;" Else Return s End If End Function </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload