首先是前台代码,主要是marquee标记的使用,还有就是如何实现js和asp.net后台变量的通信.这个技术延用了asp
时代的风格.
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default3.aspx.cs
"
Inherits
=
"
Default3
"
%>
<! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head runat = " server " >
< title > 公告栏Demo </ title >
</ head >
< body >
< form id = " form1 " runat = " server " >
< div >
<marquee behavior=scroll direction=left height=76 scrollamount=1 scrolldelay=60 onmouseover='this.stop()' onmouseout='this.start()'>
<script>
var showMsg1="<%=showMsg%>"
document.write (showMsg1);
</script>
</marquee ></ div >
</ form >
</ body >
</ html >
<! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head runat = " server " >
< title > 公告栏Demo </ title >
</ head >
< body >
< form id = " form1 " runat = " server " >
< div >
<marquee behavior=scroll direction=left height=76 scrollamount=1 scrolldelay=60 onmouseover='this.stop()' onmouseout='this.start()'>
<script>
var showMsg1="<%=showMsg%>"
document.write (showMsg1);
</script>
</marquee ></ div >
</ form >
</ body >
</ html >
下面是后台代码,从数据库取出要显示的公告内容:
using
System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/**/ /*
ASP.NET 公告栏 演示代码
* Coder LinQifo
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/**/ /*
ASP.NET 公告栏 演示代码
* Coder LinQifo
* Time:2007-11-1
*/
public partial class Default3 : System.Web.UI.Page
... {
public int noticeNum = 1;
//注意要在js中调用,必须保证访问度是protected以上级别
public string showMsg = string.Empty;//存放要显示的公告
protected void Page_Load(object sender, EventArgs e)
...{
string cmdText = "select * from Notice";
//下面代码是从数据库中取出内容
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["JustSeeOAConnectionString"].ConnectionString );
SqlCommand cmd = new SqlCommand(cmdText, conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
...{
showMsg += noticeNum .ToString ()+":"+ dr["noticeDate"].ToString () + ":" +
dr["noticeContent"].ToString () + dr["FullName"].ToString ()+" ";
noticeNum++;
}
noticeNum--;
conn.Close();
}
}
*/
public partial class Default3 : System.Web.UI.Page
... {
public int noticeNum = 1;
//注意要在js中调用,必须保证访问度是protected以上级别
public string showMsg = string.Empty;//存放要显示的公告
protected void Page_Load(object sender, EventArgs e)
...{
string cmdText = "select * from Notice";
//下面代码是从数据库中取出内容
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["JustSeeOAConnectionString"].ConnectionString );
SqlCommand cmd = new SqlCommand(cmdText, conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
...{
showMsg += noticeNum .ToString ()+":"+ dr["noticeDate"].ToString () + ":" +
dr["noticeContent"].ToString () + dr["FullName"].ToString ()+" ";
noticeNum++;
}
noticeNum--;
conn.Close();
}
}