On many of the web portals/sites it is observed that latest news start scrolling from down to top.
Requirement: Need To make following tables in SQL Server Database, and put corresponding records in the tables.
This is a very simple table structure in Master Detail format. In tbl_News all the titles and date created will be stored and corresponding newsDetail are stored in tbl_NewsDetail.
create table tbl_News
newsId int primary key identity(1,1) Not null,
newTitle varchar(50) Not null,
News Detail Table
create table tbl_NewsDetail
dtlId int primary key identity(1,1) Not Null,
newsId int foreign key references tbl_news,
Explanation in detail about the coding
In folder called as "userControll" I have web control as "Scrolling_News.ascx".
The code behind of this page i.e. on page load I have following code
private void Page_Load(object sender, System.EventArgs e)
// Put user code to initialize the page here
SqlConnection myCon = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
string strSql = "SELECT * FROM tbl_News order by dateCreated asc";
string strScrolling = "";
HtmlTableCell cellScrolling = new HtmlTableCell();
SqlCommand myComd = new SqlCommand(strSql,myCon);
sqlRdr = myComd.ExecuteReader();
strScrolling = "?Marquee OnMouseOver='this.stop();' OnMouseOut='this.start();' direction='up' scrollamount='2' bgcolor='#000000' width='40%'?";
//replace ? with < >
strScrolling = strScrolling + " ('newsDetail.aspx?NewsId="+sqlRdr.GetValue(0)
+"','NewsDetail','width=400,height=400;toolbar=no;');"+"> face='verdana' size='2' color='#ffffff'>"+ sqlRdr.GetValue(1)
strScrolling = strScrolling +"?/Marquee>";
cellScrolling.InnerHtml = strScrolling;
//close sql connection
Change the direction of the scrolling [direction='up']
Can stop on mouseover of the link [OnMouseOver='this.stop();']
Can start on mouseout of the link [OnMouseOut='this.start();']
Can controll the speed of the scrolling [direction='up' scrollamount='2']
Microsoft also provide Add rotator component which can be used with XML, but it differs with respect that
by having above functionality.
In newsDetail.aspx page, I have again simple code to get the detail based on querystring of newsId.
Using this control in a page
Register this control as below in a file in which you want to use this
<%@ Register TagPrefix="Scrolling" TagName="News" src="userControll/Scrolling_News.ascx" %>
and use this in a table as below
?table width="100%" bgColor="#ccccff">
?td width="60%">?STRONG>?FONT face="Tahoma">News Section ?/FONT? ?/STRONG? ? /td>
?td> ?SCROLLING:NEWS id="scroller" runat="server"> ?/SCROLLING:NEWS> ?/td>
Replace ? with < >
That' all enjoy...