using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
namespace Sample.NewInfo
{
/// <summary>
/// Description for NewInformation.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:NewInformation runat=server></{0}:NewInformation>"),
XmlRoot(Namespace="NewInfo")]
public class NewInformation : Microsoft.SharePoint.WebPartPages.WebPart
{
private const string defaultText = "";
private string text = defaultText;
protected System.Web.UI.WebControls.Repeater Repeater1;
[Browsable(true),
Category("Miscellaneous"),
DefaultValue(defaultText),
WebPartStorage(Storage.Personal),
FriendlyName("Text"),
Description("Text Property")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
protected override void CreateChildControls()
{
Repeater1=new Repeater();
Repeater1.ItemTemplate=new RepiTemplate();
try
{
string strConn = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
DataSet dsInfo = SqlHelper.ExecuteDataset(strConn,CommandType.Text,"SELECT TOP 10 * FROM NewInfo ORDER BY PublishDate DESC");
Repeater1.DataSource=dsInfo;
Repeater1.DataBind();
}
catch (Exception ex)
{
throw ex;
}
this.Controls.Add(Repeater1);
base.CreateChildControls ();
}
/// <summary>
/// Render this Web Part to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void RenderWebPart(HtmlTextWriter output)
{
output.Write("<div id='demo' style='overflow:hidden;height:200;width:150;vertical-align:middle'><div id='demo1' style='vertical-align:middle'>");
Repeater1.RenderControl(output);
output.Write("</div><div id='demo2' style='vertical-align:middle'></div></div>");
output.Write(@"<script Language=Javascript>
var speed=200;
demo2.innerHTML=demo1.innerHTML
function Marquee()
{
if(demo2.offsetTop-demo.scrollTop<=0)
demo.scrollTop-=demo1.offsetHeight;
else
demo.scrollTop+=2;
}
var MyMar=setInterval(Marquee,speed)
demo.onmouseover=function() {clearInterval(MyMar)}
demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
</script>");
}
}
class RepiTemplate:ITemplate
{
public RepiTemplate(){}
public void InstantiateIn(Control wc)
{
Literal l=new Literal();
l.DataBinding+=new EventHandler(this.BindData);
wc.Controls.Add(l);
}
public void BindData(object Sender,EventArgs e)
{
Literal l=(Literal)Sender;
System.Web.UI.WebControls.RepeaterItem Con=(System.Web.UI.WebControls.RepeaterItem)l.NamingContainer;
l.Text ="·<a href='"+((DataRowView)Con.DataItem)["URL"].ToString()+"'>"+((DataRowView)Con.DataItem)["Title"].ToString()+"</a><BR><BR>";
}
}
}