Last post Jul 06, 2008 02:10 PM by Mikesdotnetting
Jul 04, 2008 07:44 AM|Tikunim|LINK
I'm a newbie using VWD 2008 Express edition. I am trying to insert code on each aspx page to read a record from a table within my database, and update the page title and meta tags on my webpage.
Right now I use a datalist control to access the data and use the following code.
Protected Sub DataList2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
Dim recordcontent As String
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
RecordContent = CType(DataBinder.Eval(e.Item.DataItem, "title"), String) & vbCrLf
Page.Title = RecordContent
This works. But I think a cleaner way would be to open the database and read the record in the page load event and change the title there. Or even to have some global code somewhere that when called will return to me the title and metatags that were read.
Are there any good tutorials out there that would point to me how to do this, or can someone just step me through it.
Jul 04, 2008 01:00 PM|Mikesdotnetting|LINK
If I am dynamically populating the meta tags and page title from data I am already using on the page, I do exactly what you do. It's the most efficient approach. You don't want to be getting the same data out of the database twice for a page.
Jul 05, 2008 02:27 PM|Tikunim|LINK
I created the datalist explicitly to open the table and extract the title and meta data. The datalist is not visible to the user. The real data from the page comes from a different table. I could leave it this way, but thought that accessing the met and
title data via code would be more efficient.
Jul 05, 2008 03:58 PM|Mikesdotnetting|LINK
I could leave it this way, but thought that accessing the met and title data via code would be more efficient.
Yes, it would be more efficient. You won't be creating unnecessary objects, such as databound controls.
Jul 05, 2008 09:30 PM|Tikunim|LINK
I guess that leaves me at my original question. Are there any good tutorials out there that would point to me how to do this, or can someone just step me through it. i.e. write some code to open the database, do so sort of query, get my record and values,
and then close the db.
Jul 06, 2008 02:10 PM|Mikesdotnetting|LINK
Basic reading and writing to an Access Database code is here: