ASP.NET 公告栏 演示代码(C#)

首先是前台代码,主要是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 >

 下面是后台代码,从数据库取出要显示的公告内容:

 

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
 * 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();
    }

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值