1AnnouncementScroll.ascx
2-----------------------
3
4<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AnnounmentScroll.ascx.cs" Inherits="AnnounmentScroll" %>
5<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
6<html>
7<head>
8<title>Announcemnt Scrolling</title>
9<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
10<script type="text/javascript" language="JavaScript">
11 var Article = new Array;
12 var timer=null;
13
14 /* DEFINE SCROLLER ELEMENTS
15 Define new scroller elements here in the following format.
16 Article[i] = new Array ("display text", "URL", "frame target to load link in");i++
17 Note: If you do not want the item to be a link, change the URL value to "none".
18 */
19 ////// SCROLLER CONFIGURATION ///////////////////////////////////////////////////////////////////
20
21 orientation = "vertical" // Orientation of scroller (Horizontal or vertical)
22 scrollerWidth = "98%" // Width of entire scroller.
23 scrollerHeight = "135" // Height of Scroller.
24 borderWidth = "0" // Width of border. (use 0 for no border).
25 borderColour = "#ffffff" // Colour of scroller border. (Use either hexadecimal or text values. e.g. "#FF0000" or "Red")
26 backColour = "" // Colour of scroller background. (Use either hexadecimal or text values. e.g. "#FF0000" or "Red")
27 staticColour = "#FFFFFF" // Colour of scroller items that are NOT a link. (including scrollerDivider characters)
28 stopScroll = 1 // Pause the scroller on mouseOver. (use 0 for no.)
29 textAlignment = "left" // Alignment of each scroller item. Only really makes a difference on vertical scroller
30 // (center, left, right, justify)
31
32 // Scroller Links
33 linkFont = "Verdana" // Font of scroller links;
34 linkWeight = "normal" // Weight of scroller links;
35 linkColour = "#FFFFFF" // Colour of scroller links
36 linkSize = ".68em" // Size of links (in points)
37 linkDecoration = "none" // Decoration of links. (underline, overline, none)
38
39 // Scroller Links On MouseOver
40 slinkFont = "Verdaan" // Font of scroller links;
41 slinkWeight = "normal" // Weight of scroller links;
42 slinkColour = "#fe9b00" // Colour of scroller links
43 slinkSize = ".68em" // Size of links (in points)
44 slinkDecoration = "underline" // Decoration of links. (underline, overline, none)
45
46 scrollerDivider = "" // Character to place between each scroller item.
47 // <img> tags can be used if an image is required.
48 // Use "0" for nothing. For Vertical scrollers, it is best to use "<br>"
49
50 /*
51 Because Netscape version 4 does not support this scroller, configure the values below so NS4 users do not see an error.
52 In the scroller's place will be a static title which can be a link if require. The appearance of the static text (colour, scroller border etc)
53 will be exactly the same as for the working version in other browsers.
54 */
55 ns4Text = "Please visit Help Desk"; // Alternative text to display in Netscape 4.
56 ns4URL = "none"; // URL of link in NS4. If no URL is required, enter "none"
57 ns4Target = "_top"; // Frame target for link in NS4
58
59 ////// DO NOT EDIT BELOW THIS LINE ///////////////////////////////////////////////////////////////////
60
61 //Browser Sniffer
62 var isIE = (document.getElementById && document.all) ? true : false;
63 var isNS4 = (document.layers) ? true : false;
64 var isNS6 = (document.getElementById && !document.all) ? true : false;
65
66 style = '<style type="text/css">';
67 style += 'p{font-family:' + linkFont + '; color:' + staticColour + '; font-size:' + linkSize + 'pt; font-weight:' + linkWeight + '; text-align:' + textAlignment + '}';
68 style += 'a.rcScroller,a.rcScroller:active,a.rcScroller:visited{color:' + linkColour + ';text-decoration:' + linkDecoration + '; font-weight:' + linkWeight + '}';
69 style += 'a.rcScroller:hover{color:' + slinkColour + ';text-decoration:' + slinkDecoration + '; font-weight:' + slinkWeight + '}';
70 style += 'rcScrollerHoverNS{color:red;text-decoration:' + slinkDecoration + '; font-weight:' + slinkWeight + '}';
71 style += '<\/style>';
72
73 document.writeln(style);
74
75 // Build the scroller and place it on the page
76 function buildScroller() {
77 if (isNS4) {
78 scroller = '<table border="0" cellpadding="0" cellspacing="0" width="' + scrollerWidth + '" bgcolor="' + borderColour + '"><tr><td>'
79 scroller += '<table border="0" cellpadding="3" cellspacing="1" width="100%" height="' + scrollerHeight + '" bgcolor="' + backColour + '"><tr><td align="center" nowrap><p>';
80 if (ns4URL.toLowerCase() != "none") { scroller += '<a href="' + ns4URL + '" class="rcScroller" target="' + ns4Target + '">' + ns4Text + '</a>'; }
81 else { scroller += ns4Text; }
82 scroller += '</p></td></tr></table></td></tr></table>'
83 } else {
84 scroller = '<table border="0" cellpadding="0" cellspacing="0" style="width:' + scrollerWidth + ';height:' + scrollerHeight + ';border:' + borderWidth + 'px solid ' + borderColour + ';background-color:' + backColour + '">';
85 scroller += '<tr valign="middle"><td><div id="div" style="';
86 if (orientation.toLowerCase() == "vertical") { scroller += 'height:' + scrollerHeight + ';'; }
87 scroller += 'width:' + scrollerWidth + '; position:relative; background-color:' + backColour + '; overflow:hidden">';
88 scroller += '<div id="div1" style="position:relative; left:0; z-index:1">';
89 scroller += '<table border="0" cellpadding="0" cellspacing="0" name="table" id="table"';
90 if (orientation.toLowerCase() == "vertical") { scroller += 'style="width:' + scrollerWidth + '"'; }
91 scroller += '><tr>';
92 y = 0;
93 while (y < 4) {
94 for (x = 0; x < (Article.length); x++) {
95 if (orientation.toLowerCase() == "vertical") { scroller += '<tr>'; }
96 scroller += '<td ';
97 if (orientation.toLowerCase() == "horizontal") { scroller += 'nowrap'; } if (stopScroll == 1) { scroller += ' onMouseOver="stopScroller();" onMouseOut="setWidth()"'; }
98 scroller += '><p>';
99 if (Article[x][1].toLowerCase() != "none") {
100 scroller += '<a class="rcScroller" href="' + Article[x][1] + '" target="' + Article[x][2] + '" >' + Article[x][0] + '<\/a>';
101 } else { scroller += Article[x][0]; }
102 scroller += '</p><\/td>';
103
104 if (orientation.toLowerCase() == "vertical") { scroller += '<\/tr>'; }
105
106 if (scrollerDivider.toLowerCase() != "none") { scroller += '<td nowrap><p>' + scrollerDivider + '<\/p><\/td>'; }
107 }
108 y++
109 }
110 scroller += '<\/tr><\/table><\/div><\/div><\/td><\/tr><\/table>';
111 }
112 document.getElementById('dispItem').innerHTML=scroller;
113
114 }
115 var titleArray = new Array;
116 var linkArray = new Array;
117 var imgSRC = "<img src='/_layouts/images/mahindra/img_bullet_01.gif' width='31' border='0' align='texttop'>";
118 var blank = "_blank";
119 function AnnouncementArray(title, link) {
120 var len = titleArray.length;
121 titleArray[len++] = title;
122 var len1 = linkArray.length;
123 linkArray[len1++] = link;
124 var len2 = Article.length;
125 Article[len2] = new Array(imgSRC + title, link , blank);
126 }
127
128 // Ensure the width of the scroller is divisible by 2. This allows smooth flowing of the scrolled content
129 function setWidth() {
130 tableObj = (isIE) ? document.all("table") : document.getElementById("table");
131 obj = (isIE) ? document.all.div1 : document.getElementById("div1");
132 objWidth = (orientation.toLowerCase() == "horizontal") ? getOffset(tableObj, "width") : getOffset(tableObj, "height");
133 HalfWidth = Math.floor(objWidth / 2);
134 newWidth = (HalfWidth * 2) + 2;
135 obj.style.width = newWidth
136 moveLayer(obj, newWidth);
137
138 }
139
140 // Move the layer by one pixel to the left
141 function moveLayer(obj, width) {
142
143 maxLeft = (0 - (width / 2) + 2) / 2
144 if (orientation.toLowerCase() == "horizontal") {
145 obj.style.left = (parseInt(obj.style.left) <= maxLeft) ? 0 : parseInt(obj.style.left) - 1
146 } else {
147 if (obj.style.top == "") { obj.style.top = 0; }
148 // alert(obj.style.top)
149 if (parseInt(obj.style.top) < (0 - (width / 2) + 6)) {
150 obj.style.top = 0
151 } else {
152 obj.style.top = parseInt(obj.style.top) - 1
153 }
154 }
155 timer = setTimeout("moveLayer(obj, " + width + ");", 65);
156 }
157
158 // Get width and height of layer
159 function getOffset(obj, dim) {
160 if (dim == "width") {
161 oWidth = obj.offsetWidth
162 return oWidth
163 }
164 else if (dim == "height") {
165 oHeight = obj.offsetHeight
166 return oHeight
167 }
168 }
169
170 function stopScroller() {
171 clearTimeout(timer)
172 }
173
174
175
176 function runScroller() {
177
178 if (!isNS4) { setWidth() }
179 }
180 ////// END OF SCRIPT ///////////////////////////////////////////////////////////////////
181
182</script>
183</head>
184<body onload="runScroller()">
185<div id='dispItem'>
186</div>
187</body>
188</html>
189
190
191AnnouncementScroll.ascx.cs
192--------------------------
193
194using System;
195using System.Collections.Generic;
196using System.Web;
197using System.Web.UI;
198using System.Web.UI.WebControls;
199using Microsoft.SharePoint;
200using System.Data;
201using System.Text;
202
203public partial class AnnounmentScroll : System.Web.UI.UserControl
204{
205 protected void Page_Load(object sender, EventArgs e)
206 {
207 try
208 {
209 StringBuilder jScript = new StringBuilder();
210
211 SPSite site = new SPSite("http://servername/sites/ASCETemp/");
212 SPWeb web = site.OpenWeb();
213
214 string AnnouncementQuery = "<Query></Query>";
215 DataTable dtAnnouncementList1 = GetQueryResult("Announcements", AnnouncementQuery, "CodingView");
216
217 DataView dv = new DataView(dtAnnouncementList1);
218 dv.Sort = "ID DESC";
219 DataTable dtAnnouncementList = dv.ToTable();
220 int count = dtAnnouncementList.Rows.Count;
221
222 List<String> Announcement = new List<String>();
223 string URL = string.Empty;
224 string imgSRC = "<img src='/_layouts/images/mahindra/img_bullet_01.gif' width='31' border='0' align='texttop'>";
225 string blank = "_blank";
226 jScript.Append("<script type='text/javascript' language='JavaScript'> ");
227
228 string title = string.Empty;
229 string link = string.Empty;
230 for (int i = 0; i < count; i++)
231 {
232 DataRow dtRow = dtAnnouncementList.Rows[i];
233 title = dtRow["Title"].ToString().Trim();
234 link = dtRow["Link"].ToString().Trim();
235
236 jScript.Append("AnnouncementArray('" + title + "','" + link + "');");
237 }
238
239 jScript.Append("buildScroller();");
240 jScript.Append("</script>");
241
242 this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Announcement", jScript.ToString(), false);
243 }
244 catch (Exception ex)
245 {
246 }
247 }
248 #region Site List Access Functions ...
249
250 public DataTable GetQueryResult(string strListName, string strQuery, string strListView)
251 {
252 DataTable dtQuery = new DataTable();
253 SPListItemCollection itemColl = null;
254
255 //get the datatable containing for the list & the specified query
256 if (strListName != string.Empty && strQuery != string.Empty)
257 {
258 try
259 {
260 SPList lst = ReturnList(strListName);
261 SPQuery query = new SPQuery(lst.Views[strListView]);
262 query.Query = strQuery;
263 itemColl = lst.GetItems(query);
264 dtQuery = itemColl.GetDataTable();
265 if (dtQuery.Rows.Count == 0)
266 {
267 dtQuery = null;
268 }
269 }
270 catch (Exception ex)
271 {
272
273
274 }
275 }
276 return dtQuery;
277 }
278
279 public SPList ReturnList(string strListName)
280 {
281 string url = string.Empty;
282 SPSite site;
283 SPWeb web = null;
284 try
285 {
286 url = this.GetSiteName();
287 SPSecurity.RunWithElevatedPrivileges(delegate()
288 {
289 site = new SPSite(url);
290 web = site.OpenWeb();
291 });
292
293 web.AllowUnsafeUpdates = true;
294 }
295 catch (Exception ex)
296 {
297
298 }
299
300 return web.Lists[strListName];
301 }
302
303 public string GetSiteName()
304 {
305 string strSiteName = string.Empty;
306 try
307 {
308 strSiteName = "http://servername/sites/ASCETemp/";
309 }
310 catch (Exception ex)
311 {
312
313 }
314
315 return strSiteName;
316 }
317 #endregion
318
319}