Click here to Skip to main content
12,454,965 members (53,997 online)
Click here to Skip to main content
Add your own
alternative version


50 bookmarked

Fully Customized Reusable ASP+ Vertical/Horizontal Marquee Consuming XML/MS SQL

, 23 May 2005
Rate this:
Please Sign up or sign in to vote.
Vertical/horizontal Marquee Web Custom Control consuming SQL Server DB/XML, with great design time attributes.


In every project I need a way to show the latest articles, news, weathercast, etc. Some projects process links with query strings while others not.. My ideal solution would be a quick, simple, lightweight Marquee Web Custom Control...

If you are not familiar with custom web controls, here is a partial definition from the Microsoft documentation:

Web controls run on the server and include form controls such as buttons and text boxes, as well as special purpose controls such as a calendar. This allows you to programmatically control these elements on a web page. Web controls are more abstract than HTML controls. Their object model does not necessarily reflect HTML syntax. (See MSDN.)


  • great design-time attributes.
  • allows you to choose database: XML or SQL Server.
  • you can apply your web template.
  • each topic has ID, description, date, anchor URL, anchor text.


In the case of XML as database:

<?xml version="1.0" encoding="utf-8" ?> 
    <topic tpID='1' postDate='1/1/2002'>
        <url value=''> Link... </url>
        <hint><![CDATA[ Link Description goes here ]]></hint>

Using the code

Our control has three classes:

  • Marquee: WebControl (which renders the control).
  • Data (reads data from database (XML or SQL Server) and generates a collection of topics).
  • Anchor (data holder).

First, we will preview the Data class code:

public class Data
    public ArrayList GetNews(string str,bool _isXML)
        //setup Array List
        ArrayList AnchorsArrayList=new ArrayList();

        if(!_isXML)// Read From MSSQL DB :::::::::::::
                //Select SQl Query : text,url,id,date,title , Table Name links
                string sqlSelectStr="SELECT text, url, id, date, title FROM links";
                SqlConnection myConnection;

                //connect DB And check without overload on the DB Server.
                myConnection=new SqlConnection(str);

                //pass our SQL Str within new Command
                SqlCommand myCommand=new SqlCommand(sqlSelectStr,myConnection);

                //Creating  A Reader to store Returned Database Data
                SqlDataReader myReader=myCommand.ExecuteReader();

                //looping thrugh Reader.
                    //intialize Anchor Object
                    Anchor anc=new Anchor();
                    //set Object id
                    //set Object url
                    //set Object text
                    //set Object date
                    //set Object Hints

                    //add it to our Collection
                //Dispose any relation with DB
            catch(Exception ex)
                throw ex;
        else // Read From XML DB ::::::::::::::::::::::::::::::::::
                // create XMLDocument and Load Xml File
                XmlDocument xmlDoc=new XmlDocument();

                //create XPath Navigator in order to navigate XML Nodes...
                XPathNavigator nav=xmlDoc.CreateNavigator();

                // create Two NodeItrators in order to loop throw Topics
                XPathNodeIterator navIterator;//topic
                XPathNodeIterator navIterator2;//details

                //Set XPath to Topic Node...

                //topic number
                int topicNo=1;
                    //intialize Anchor Object
                    Anchor anc=new Anchor();

                    //read current topic ID and Date...I didnt 
                    //use id or Date in this article 
                    //but you can use it in sorting 
                    //search or Quary Strings between pages
                    //set Anchor/Link details XPath  

                    //read URL and Text o the current topic

                    //set description XPath  

                    //finally... Save Our Link


            catch(Exception ex)
                throw ex;
        //you are welcome......
        return AnchorsArrayList;

Now we look at the Marquee class. There are two methods:

  • Render(...)
  • AnchorsListHtmlGenerator(.....)
///    <summary>
///     Generate Links Html Tags according to user setting.
///    </summary>
///    <param name="aList">Type:ArrayList :collection
///                        of Anchor Objects</param>
///    <returns>HTML as string</returns>
protected string AnchorsListHtmlGenerator(ArrayList aList)
    StringBuilder s = new StringBuilder();
    string dir;
    bool pFlag;

    //Set Langauge Direction Left-Right or Right-Left
    if (arabicSupport){dir = "rtl";}else{dir = "ltr";}

    //Set Marquee direction up-Down-Let-Right using enum
    switch (marqueeDirection)
        case Direction.up:
        case Direction.down:
                pFlag = true;
                pFlag = false;

    //looping through Arraylist    collection of Links.
    for (int i = 0; i < aList.Count; i++)
        //Check    If User    need to    Show Hints Or not.
        if (showTitle)
            //Is Bold
            if (TitleFontBold) { s.Append("<b>"); }

            // <p> tag
            if (pFlag) { s.Append("<p dir=\"" + dir + "\">"); }

            //Font and Size
            s.Append("<font    size=\"" + titleFontSize +
                     "\" color=\"" +
                     urlTitleForeColor.Name.ToString() +
                     "\"" + ">");

            //retrive Titles by    looping    through    Passed ArrayList


            if (pFlag) { s.Append("</p>"); }

            if (TitleFontBold) { s.Append("</b>"); }

        //<p> tag and set Direction
        if (pFlag) { s.Append("<p dir=\"" + dir + "\">"); }

        //set Image    Source
        if (showImage)
            s.Append("<img    src=" + listItemImageSrc + ">");

        //<a> Tag
        s.Append("<A href=\"");
        //retrive and set Url from Passed ArrayList

        //URL UnderLine    Check and close    </a>
        if (urlUnderLine)
            s.Append(" style=\"text-decoration:    none\" ");

        //Set text Font&Color
        s.Append("<font    size=\"");
        s.Append(linkFontSize + "\"    color=\"" +
           urlForeColor.Name.ToString() + "\"" + ">");

        if (pFlag) { s.Append("</p><p> </p>"); }

    //Return Full HTML Code    As String
    return s.ToString();

Render method:

/// <summary>
/// Render this control to web solution
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
        // make instance from Data Class
        Data myData = new Data();
        //Write Marquee Tag with Custome Attributes
        output.Write("<marquee onmouseover=this.stop() " +
                     "onmouseout=this.start() scrollamount=1 " +
                     "scrolldelay=10 direction=" +
                     marqueeDirection.ToString() + " width=" +
                     width + " height=" + height + ">");
        //check Bold Option
        if (FontBold) { output.Write("<b>"); }
        //write the Links Tag which returned 
        //by GetNew(connectionStr) Method
        //Bold Close Tag
        if (FontBold) { output.Write("</b>"); }
        //Marquee Close Tage

    catch (Exception ex)


How? ..

After registering the DLL file within your web solution, you must:

  • Decide the database type: XML Or MS SQL Server. If your choice is XML, then set the property IsXML=true.

  • Then specify your XML file full path ConnectionString="C:\resources\xml\XMLFile1.xml" or your MS SQL DB connection string in the case of IsXml=false...


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Ameen Abudbash
Team Leader
Egypt Egypt
• Over 8 years of experience in software developing, designing and implementing High Available web based applications specialized in Microsoft & IBM technologies.
• Extensive experience in developing, designing and implementing ECM solutions using IBM Filenet,Workplace, IBM BPM, REST services, AND Partial Experience in major CMS (Documentum and Oracle ECM).
• Extensive experience in Designing & Implementing Web2 Enterprise Apps using Leading RIA Frameworks (ExtJs , YUI… ).
• Partial experience in development with Microsoft SharePoint 2007 & 2010.
• Practical experience in Microsoft BI tools SSAS, SSIS, SSRS and Excel Services.
• Deep understanding of the OOP and Strong Design patterns background
• Interactive and fast enough to learn new technologies and sciences.

• Extensive experience in problem-to-resolution troubleshooting skills
• Playing different IT roles including designing, implementing, supporting, consulting and development, Managing teams composed of analyst, developers & QA.
• Agile project management methodologies and managed teams with Scrum.
• Deliver technical workshops, presentations, documents and POCs.

You may also be interested in...


Comments and Discussions

QuestionHow can you change the Scrolling speed? Pin
mikelopilato28-May-09 8:49
membermikelopilato28-May-09 8:49 
QuestionSQL Dataviews Pin
Tcode26-Aug-08 11:00
memberTcode26-Aug-08 11:00 
QuestionHow to use this control Pin
SharonRao27-Feb-07 12:23
memberSharonRao27-Feb-07 12:23 
GeneralNew to .Net Pin
mikelopilato25-Oct-06 14:36
membermikelopilato25-Oct-06 14:36 
GeneralText Coloring &amp; Refersh Pin
Aviram Solomon17-Oct-05 5:10
memberAviram Solomon17-Oct-05 5:10 
GeneralUsing Database values and the URL Pin
aschell13-Jul-05 4:18
memberaschell13-Jul-05 4:18 
GeneralRe: Using Database values and the URL Pin
Ameen Abudbush13-Jul-05 20:45
memberAmeen Abudbush13-Jul-05 20:45 
GeneralRe: Using Database values and the URL Pin
mikelopilato28-May-09 8:48
membermikelopilato28-May-09 8:48 
GeneralMarquee Hesitattes on the browser Pin
pkonaje6-Jun-05 18:07
memberpkonaje6-Jun-05 18:07 
GeneralRe: Marquee Hesitattes on the browser Pin
scscsc7-Jun-05 22:57
memberscscsc7-Jun-05 22:57 
GeneralGood Job... Pin
ncsol4-Jun-05 8:36
memberncsol4-Jun-05 8:36 
GeneralScreenshot Pin
Novacaine1-Jun-05 6:48
memberNovacaine1-Jun-05 6:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 24 May 2005
Article Copyright 2005 by Ameen Abudbash
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid