I have a query where I want to select the blog posts in my database and then display that date and title on a page. I also need to display a link to open a new page with a querystring that will allow the user to read the entire blog post. Each querystring
should include the BlogID.
I would like to place all posts in a datatable and then For Each...Next.
However, I do not know how to finish it.
Here is my code.
Thanks.
'''''''''''''''Code Behind
Dim connstrBlog As String = ConfigurationManager.ConnectionStrings("String").ToString()
Dim sqlStrBlog As String = "SELECT PostTitle, CONVERT (char(10), DateCreated, 101) AS DateCreated, Post, BlogID FROM Blog"
Dim dtBlog As New DataTable
Dim dataAdapterBlog As New SqlClient.SqlDataAdapter(sqlStrBlog, connstrBlog)
dataAdapterBlog.Fill(dtBlog)
dataAdapterBlog.Dispose()
For Each drBlog As DataRow In dtBlog.Rows
BlogLink.HRef = "ReadBlog.aspx?search=" + drBlog(3).ToString()
BlogDateLabel.Text += "<h5>" + drBlog(0).ToString() + "</h5>"
BlogDateLabel.Text += "<h6>" + drBlog(1).ToString() + "</h6>"
BlogDateLabel.Text += HttpUtility.HtmlDecode(drBlog(2).Substring(0, 100)) + "..."
BlogDateLabel.Text += "<br /><br />"
Next
'''''''''''''''''HTML page
<a id="BlogLink" runat="server"><asp:Label ID="BlogDateLabel" runat="server"></asp:Label></a>
mattcase
Member
374 Points
518 Posts
For each row in datable with Hyperlink
Sep 26, 2012 03:09 PM|LINK
Hi,
I have a query where I want to select the blog posts in my database and then display that date and title on a page. I also need to display a link to open a new page with a querystring that will allow the user to read the entire blog post. Each querystring should include the BlogID.
I would like to place all posts in a datatable and then For Each...Next.
However, I do not know how to finish it.
Here is my code.
Thanks.
'''''''''''''''Code Behind Dim connstrBlog As String = ConfigurationManager.ConnectionStrings("String").ToString() Dim sqlStrBlog As String = "SELECT PostTitle, CONVERT (char(10), DateCreated, 101) AS DateCreated, Post, BlogID FROM Blog" Dim dtBlog As New DataTable Dim dataAdapterBlog As New SqlClient.SqlDataAdapter(sqlStrBlog, connstrBlog) dataAdapterBlog.Fill(dtBlog) dataAdapterBlog.Dispose() For Each drBlog As DataRow In dtBlog.Rows BlogLink.HRef = "ReadBlog.aspx?search=" + drBlog(3).ToString() BlogDateLabel.Text += "<h5>" + drBlog(0).ToString() + "</h5>" BlogDateLabel.Text += "<h6>" + drBlog(1).ToString() + "</h6>" BlogDateLabel.Text += HttpUtility.HtmlDecode(drBlog(2).Substring(0, 100)) + "..." BlogDateLabel.Text += "<br /><br />" Next '''''''''''''''''HTML page <a id="BlogLink" runat="server"><asp:Label ID="BlogDateLabel" runat="server"></asp:Label></a>Curt_C
All-Star
66017 Points
7639 Posts
Moderator
Re: For each row in datable with Hyperlink
Sep 26, 2012 05:20 PM|LINK
Have you looked at a Repeater control? That may be the easiest way to do what you are after.
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
Tim Cadieux
Participant
966 Points
317 Posts
Re: For each row in datable with Hyperlink
Sep 26, 2012 06:18 PM|LINK
This article has downloadable source showing how to use Nested Repeaters
http://everymanprogrammer.com/index.php/nested-repeaters-do-it-clean-and-simple-a-beginners-tutorial-part-1/
***
Mark the replies as Answers if they answered your question.