So I have been modding the small business toolkit to my liking. Since I have had so much help on the site here I figured I would give back.
Out of the box the toolkit has a static news list on the home page, under Recent News. I now have successfully put in a repeator and pulled from the XML to create a list that updates when you update the XML.
I am going to try and list the directions here, make sure you make backups of each file because most of this is from memory on how I did this.
Open App_code/News/News.vb
I added it after the method GetAllNews...
' <summary>
' Returns Latest 5 news items
' </summary>
Public Shared Function GetTop5News() As List(Of NewsItem)
Return Provider.GetTop5News()
End Function 'New
Next open App_code/News/NewsProvider.vb
Add it after GetAllNews method...
Public MustOverride Function GetTop5News() As List(Of NewsItem)
Next open App_code/News/SqlNewsProvider.vb, I don't use SQL so I cannot vouch for this code....
' <summary>
' Get the latest 5 news articles
' </summary>
Public Overrides Function GetTop5News() As List(Of NewsItem)
Dim list As List(Of NewsItem) = New List(Of NewsItem)
' create a connection, invoke a stored procedure and add results to a list
Dim con As New SqlConnection(connectionString())
Try
con.Open()
Dim cmd As New SqlCommand("GetNews", con)
Dim r As SqlDataReader = cmd.ExecuteReader()
Dim curr As NewsItem
While r.Read()
If TypeOf r("id") Is DBNull Or TypeOf r("visible") Is DBNull Or TypeOf r("title") Is DBNull Then
Throw New InvalidOperationException(Messages.NewsItemRequiredAttributesMissing)
End If
curr = New NewsItem(CStr(r("id")), CType(r("visible"), [Boolean]), CStr(r("title")))
curr.Date = Util.ReturnEmptyStringIfDbNull(r("date"))
curr.Content = Util.ReturnEmptyStringIfDbNull(r("content"))
curr.ImageUrl = Util.ReturnEmptyStringIfDbNull(r("imageUrl"))
curr.ImageAltText = Util.ReturnEmptyStringIfDbNull(r("imageAltText"))
list.Add(curr)
End While
con.Close()
Finally
con.Dispose()
End Try
Return list
End Function'New
Next we do App_code/News/XmlNewsProvider.vb
'/ <summary>
'/ Returns latest news items
'/ </summary>
Public Overrides Function GetTop5News() As List(Of NewsItem)
Dim dataSet As DataSet = Util.ReadAndValidateXml(_xmlFile, _xsdFile)
Dim list As List(Of NewsItem) = New List(Of NewsItem)
Dim t As DataTable
Dim c As Int16
For Each t In dataSet.Tables
Dim curr As NewsItem
Dim r As DataRow
For Each r In t.Rows
curr = New NewsItem(CStr(r("id")), CBool(r("visible")), CStr(r("title")))
curr.Date = Util.ReturnEmptyStringIfDbNull(r("date"))
curr.Intro = Util.ReturnEmptyStringIfDbNull(r("intro"))
curr.Content = Util.ReturnEmptyStringIfDbNull(r("content"))
curr.ImageUrl = Util.ReturnEmptyStringIfDbNull(r("imageUrl"))
curr.ImageAltText = Util.ReturnEmptyStringIfDbNull(r("imageAltText"))
list.Add(curr)
Next r
Next t
c = list.Count()
c = c - 4
list.RemoveRange(0, c)
list.Reverse()
Return list
End Function'New
This all your updating in the app_code files.
Now you must add an objectdatasource and a repeater to your home page....Save all files.
Open Default.aspx in design mode. Drag on an objectdatasource from your toolbox, click configure data source. uncheck show only data components, in the drop down select News, click NEXT On the next drop down select GetTop5News() and click FINISH
Drag a Repeater onto the page and then within the built in controls select the objectdatasource you just created within the drop down.
Finally go into the HTML and fix it up as so...remember to put it within the UL tags so that you can get that list look! I cannot remember if you need to edit the XSD file as it was a while ago that I created this (I most recently put my catalog items in a list similar to this on the home page, let me know how it goes!
Not only does this post give a useful addition to a website, but it really explains how to do some key things. THANKS -- see
http://www.hillcresthsdallas.org to see what you helped with.
Kath great to hear, I wasn't sure if I explained it quite well. When I get some time I will post the one for the catalog if you want those items to be posted to the front page dynamically too.
Horizon
Member
155 Points
79 Posts
Adding Dynamic Top 5 News List On Home Page
Nov 03, 2008 02:40 PM|LINK
So I have been modding the small business toolkit to my liking. Since I have had so much help on the site here I figured I would give back.
Out of the box the toolkit has a static news list on the home page, under Recent News. I now have successfully put in a repeator and pulled from the XML to create a list that updates when you update the XML.
I am going to try and list the directions here, make sure you make backups of each file because most of this is from memory on how I did this.
Open App_code/News/News.vb
I added it after the method GetAllNews...
' <summary> ' Returns Latest 5 news items ' </summary> Public Shared Function GetTop5News() As List(Of NewsItem) Return Provider.GetTop5News() End Function 'NewNext open App_code/News/NewsProvider.vb
Add it after GetAllNews method...
Next open App_code/News/SqlNewsProvider.vb, I don't use SQL so I cannot vouch for this code....
Next we do App_code/News/XmlNewsProvider.vbThis all your updating in the app_code files.
Now you must add an objectdatasource and a repeater to your home page....Save all files.
Open Default.aspx in design mode.
Drag on an objectdatasource from your toolbox, click configure data source.
uncheck show only data components, in the drop down select News, click NEXT
On the next drop down select GetTop5News() and click FINISH
Drag a Repeater onto the page and then within the built in controls select the objectdatasource you just created within the drop down.
Finally go into the HTML and fix it up as so...remember to put it within the UL tags so that you can get that list look! I cannot remember if you need to edit the XSD file as it was a while ago that I created this (I most recently put my catalog items in a list similar to this on the home page, let me know how it goes!
KathWeaver
Member
2 Points
1 Post
Re: Adding Dynamic Top 5 News List On Home Page
Nov 06, 2008 03:27 AM|LINK
You rock!
Not only does this post give a useful addition to a website, but it really explains how to do some key things. THANKS -- see http://www.hillcresthsdallas.org to see what you helped with.
Horizon
Member
155 Points
79 Posts
Re: Adding Dynamic Top 5 News List On Home Page
Nov 07, 2008 01:13 AM|LINK
Kath great to hear, I wasn't sure if I explained it quite well. When I get some time I will post the one for the catalog if you want those items to be posted to the front page dynamically too.