How do I cycle through and display text from a set of records, one record at a time at a set interval (i.e. news pager)?

I am trying to display alerts, one record at a time from a database, that cycle to the next or first record at a set interval. I am essentially trying to have a slide show, but for text only.

I am using a similar solution for displaying images with the slideshowextender, but need the effect for text only. This is my current image solution:

I would also be open to this kind of solution, again, if it worked for text...

Help help!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are you ok with pulling the next alert from a cached source for a specified time period? For example, you could load all of your results into a list which is cached with an expiration of lets say 5 minutes. Then on your actual web page you could then just refresh an updatepanel every 30 seconds or so and loop through the cached list. This would reduce your calls to the database significantly and wouldn't be too complex to implement. The downside with this is that if a new alarm was added, it wouldn't show up on your alert list until the next time the cache was refreshed (unless you used sql dependencies, of course).
devo00Author Commented:
Hi aternex, that's fine, but I still need to know how to implement a cycling text alert dataset first and worry about database hits second.
Fair enough, here is an example. I'm sure there are a couple of other ways to do this, but this one was pretty easy.

Here is a generic web page that shows the cached object being looped through

Imports System.Web.Caching

Public Class _Default
  Inherits System.Web.UI.Page

  Dim alerts As List(Of Alert)

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If alerts Is Nothing Then
      alerts = Cache("Alerts")
    End If

    Dim currentItem As Integer = alerts.IndexOf(lblTest.Text)

    If currentItem >= 0 AndAlso currentItem < alerts.Count - 1 Then
      lblTest.Text = alerts(currentItem + 1)
      lblTest.Text = alerts(0)
    End If
  End Sub
End Class

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <asp:Label ID="lblTest" runat="server" />
        <asp:Timer ID="Timer1" runat="server" Enabled="true" Interval="5000" />
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />

Open in new window

In one application I developed, I had to ensure that nearly all foreign key data was always available. To accomplish this, I used the code pattern below to ensure data was cached and as current as the business demanded. This would show how you could populate your list and have it expire

Imports System.Configuration.ConfigurationManager
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Caching

Public Class CacheHelper
  Private onRemove As CacheItemRemovedCallback = Nothing

  Public Sub New()
    onRemove = New CacheItemRemovedCallback(AddressOf CacheReset)
  End Sub

  ' Fills the cache object with list of alerts
  ' duration is expected to be the number of minutes the cache is valid for
  ' I just put in a simple alert class, so obviously you would need to
  ' modify this to fit your requirements
  Public Sub PopulateCache(ByVal duration As Integer)
    Dim Alerts As New List(Of Alert)

    Using oConn As New SqlConnection(ConnectionStrings("MyDatabase").ConnectionString)
      Using oCmd As SqlCommand = oConn.CreateCommand()
        oCmd.CommandType = CommandType.StoredProcedure
        oCmd.CommandText = "dbo.GetOpenAlerts"


        Using oRs As SqlDataReader = oCmd.ExecuteReader(CommandBehavior.CloseConnection)
          While oRs.Read()
            Dim item As New Alert

            item.ID = oRs("ID")
            item.Message = oRs("Message")
            item.CreateDate = oRs("CreateDate")


          End While
        End Using
      End Using
    End Using

    ' The reason I am using insert instead of add is that insert replaces the
    ' cache object if it already exists.
    System.Web.HttpRuntime.Cache.Insert("Alerts", Alerts, Nothing, DateTime.UtcNow.AddMinutes(duration), Cache.NoSlidingExpiration, CacheItemPriority.Normal, onRemove)
  End Sub

  ' The purpose of this routine is to reinsert the object that was just removed
  ' from the cache quickly for a short period of time. The duration should be
  ' long enough to cover the time required for your database query to
  ' return the results. This ensures that data is always available to 
  ' people requesting it as quickly as possible, but won't let the data
  ' become to stale.
  Public Sub ReloadCache(ByVal key As String, ByVal value As Object)
    System.Web.HttpRuntime.Cache.Insert(key, value, Nothing, DateTime.UtcNow.AddMinutes(1), Cache.NoSlidingExpiration, CacheItemPriority.Normal, onRemove)
  End Sub

  ' Once an object is removed, the cache needs to be recreated -- unless
  ' it was purposely removed or hasn't been used often. This fit the 
  ' requirements that I had to meet, but you can change if you need.
  Public Sub CacheReset(ByVal key As String, ByVal value As Object, ByVal reason As CacheItemRemovedReason)
    If reason = CacheItemRemovedReason.Removed OrElse reason = CacheItemRemovedReason.Underused Then
      Exit Sub
    End If

    ' Put the object that was just removed back into the cache
    ReloadCache(key, value)

    ' Recreate the cache with the new object
  End Sub
End Class

Open in new window

Then in the global.asax.

  Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    Dim helper As New CacheHelper
    helper = Nothing
  End Sub

Open in new window

I hope this is somewhat helpful. Hopefully I didn't make any typing errors.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

For the sake of argument, change it from a List(Of Alert) to a List(Of String) and this example will work. Also, since you mentioned a dataset, you might look into the select method of the underlying datatable to find the row index and use it to loop through to the next one. Again, as with everything in .net there are tons of ways to accomplish the same thing. Sorry if I've provided more confusion than assistance.
Carlos VillegasFull Stack .NET DeveloperCommented:
I think that you can use the JQuery library to accomplish this, do you use it in your project? it is very light and I found it very usefull in my projects, here is a small example that I think you want to do:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
    <title>Rotate Text Example</title>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        var textToDisplay = ['Hello', 'World', 'This', 'Is', 'A', 'Test!'];

        function startRotate(arr) {
            var tc = $('#textContainer');

            if ($.isArray(arr)) {
                tc.stop(true).fadeTo('1', 1).fadeOut('slow', function () {
                    textToDisplay = arr;

            for (var i in textToDisplay) {
                (function (i) {
                        function () {
                            document.getElementById('textContainer').innerHTML = textToDisplay[i];
                        function () {
                            if (i == textToDisplay.length - 1)

        $(document).ready(function () {

        function updateText() {
            startRotate(['Breaking New\'s!!!', 'This Is...', 'A New...', 'Test...']);
    <h1 id="textContainer"></h1>
    <br />
    <button onclick="updateText()">Update Text</button>

Open in new window

Then you can make a Ajax response to the page for update the text using the "startRotate" function and passing an array of strings.

I tested it in Chrome, FF and IE9 and works fine.

I hope it is what you need to solve your problem.
devo00Author Commented:
aternex, I'm having trouble converting this to c#, particularly here:
onRemove = New CacheItemRemovedCallback(AddressOf CacheReset)

Do you happen to have this in c#?
Carlos VillegasFull Stack .NET DeveloperCommented:
If you allow me...

System.Web.Caching.CacheItemRemovedCallback onRemove = new System.Web.Caching.CacheItemRemovedCallback(CacheReset);

Open in new window

void CacheReset(string key, object value, System.Web.Caching.CacheItemRemovedReason reason)
    switch (reason)
        case System.Web.Caching.CacheItemRemovedReason.Removed:
        case System.Web.Caching.CacheItemRemovedReason.Underused:

    // Put the object that was just removed back into the cache
    ReloadCache(key, value);

    // Recreate the cache with the new object

Open in new window

devo00Author Commented:
Great answers, I used jQuery but will apply caching as well. Marked partially only because one answer was in VB.
Carlos VillegasFull Stack .NET DeveloperCommented:
Glad to help you dude
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.