SharePoint News Ticker WebPart

Most of the news websites contain news tickers. There are several JQuery plugins available for doing this.
My requirement was to use the News Ticker in SharePoint webpart page and the news items needed to be read from a SharePoint list like announcements.

Here is how it can be done. First download the news ticker js file from here.
Also download the latest minified jquery file from here:

Now create a SharePoint Empty project named TickerWebparts. Then Add a Visual Webpart project to the solution. Name it NewsTickerWebpart. Add a SharePoint "Layouts" Mapped folder to the solution. The javascript files will be placed here. The solution structure should look like this.

Copy both jquery.min.js and newsticker.js files in the JS folder inside TickerWebparts folder in Layouts folder. Notice that I have changed the name of the jquery.min.js file to jquery.1.6.2.min.js in order to recognize the version of Jquery.
Open the .ascx contol in design mode and paste the following code in it after all the import and register statements.

<script type="text/javascript" src="/_layouts/TickerWebparts/JS/jquery.1.6.2.min.js"></script>
<script type="text/javascript" src="/_layouts/TickerWebparts/JS/jquery.newsticker.js"></script>
<script type="text/javascript">
       function () {
<style type="text/css">
.newsticker {
       list-style-type: none;
<asp:Label ID="lblNews" runat="server"></asp:Label>

Open the webpart cs file, in our case NewsTickerWebpart.cs file and paste the following code inside the class.

private const string _ascxPath = @"~/_CONTROLTEMPLATES/TickerWebparts/NewsTickerWebpart/NewsTickerWebpartUserControl.ascx";

        private StringBuilder listElements = new StringBuilder();
        Control control = null;
        [WebDisplayName("List name")]
        [WebDescription("Enter the name of the list.")]
        public string ListName

        protected override void CreateChildControls()
            control = Page.LoadControl(_ascxPath);

        protected override void RenderContents(HtmlTextWriter writer)
            Label label = (Label)control.FindControl("lblNews");
            if (string.IsNullOrEmpty(ListName))
                label.Text = "News ticker webpart is not configured. Please enter the name of                   the list.";
                    listElements.Append("<ul id='news'>");
                    SPWeb web = SPContext.Current.Web;
                    SPList list = web.Lists[ListName];
                    SPListItemCollection items = list.Items;
                    foreach (SPListItem item in items)
                        string title = item.Title;
                    listElements.Append("</ul> ");
                catch (Exception ex)
                    label.Text = ex.Message;



 Build and deploy the solution and add the webpart to the page. Provide the name of the list which contains news in the configuration section of the webpart