滚动新闻控件的ASP.NET与C#实现

       我们在浏览网站的时候,总能看到关于最新的网站信息滚动列出,通常这是用脚本代码编写而成的,很繁琐!这里介绍用web控件实现其功能!该控件已经在主流的浏览器上测试过,运行良好!
       实现这个功能的前提是要设计一个主从详细显示的数据库,为方便操作,我在系统给的NorthWind数据库中加入了两个表,这两个表结构很简单的!
表一News Table:
create table tbl_News
(
 newsId  int  primary key identity(1,1) Not null,
 newTitle varchar(50) Not null,
 dateCreated datetime
)

表二News Detail Table
create table tbl_NewsDetail
(
 dtlId  int  primary key identity(1,1) Not Null,
 newsId  int foreign key references tbl_news,
 newsDetail varchar(8000)
)
      完后,读者可以随意的输入些新闻的信息,要不然程序运行的时候,将看不到任何效果!
关于代码的详细说明:
      1、我建立的控件"Scrolling_News.ascx"放在文件夹“userControll”中,这只是为了便于有效管理!在该控件中,我放置了一个table控件,相应的HTML源码如下:
<TABLE id="tblScrolling" cellSpacing="1" cellPadding="1" width="100%" border="0" runat="server">
 <TR id="rowScrolling" runat="server"></TR>
</TABLE>
       这个控件主要是查找新闻主表,按照创建日期进行排序,给出当前新闻的宏观展示。相关代码如下:

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);
   SqlDataReader sqlRdr;
   try
   {
    myCon.Open();
    sqlRdr = myComd.ExecuteReader();
    strScrolling = "<Marquee OnMouseOver='this.stop();' OnMouseOut='this.start();' direction='up' scrollamount='2' bgcolor='#000000' width='40%'>";
    while(sqlRdr.Read())
    {
     strScrolling = strScrolling + "<a href='#' OnClick="+"javascript:window.open('newsDetail.aspx?NewsId="+sqlRdr.GetValue(0)+"','NewsDetail','width=400,height=400;toolbar=no;');"+"><font face='verdana' size='2' color='#ffffff'>"+ sqlRdr.GetValue(1) +"</a>&nbsp;&nbsp;"+sqlRdr.GetValue(2).ToString()+"</font><br><br>";
    }
    strScrolling = strScrolling +"</Marquee>";
    sqlRdr.Close();
    cellScrolling.InnerHtml = strScrolling;
    rowScrolling.Cells.Add(cellScrolling);   
   }
   catch(Exception msg)
   {
    Response.Write(msg.Message);
   }
   finally
   {
    //close sql connection    
    myCon.Close();
   }
  }  
        这段代码主要指明了新闻滚动的方向、鼠标指向某条新闻时的动作、鼠标离开某条新闻时的动作以及新闻滚动的速度,你可以修改相应的设置查看效果!值得说明的是所有这些设定都被包含在<Marquee></Marquee>中,点击某条信息时,将转到newsDetail.aspx页面进行处理! 
        [注:关于Marquee标志,读者可到http://www.asp78.com/ArticleShow.asp?ArticleID=92去查看,简单来说添加  它后有滚动效果了!]
       2、在newsdetails.aspx中,其根据传递过来的新闻标号进行处理,读取对应的新闻详细信息,并将其内容添加到newsdetails.aspx页面中显示出来,该页面的大小等信息已经限定,表面上看来好象是以个弹出窗口的形式显示!详细的代码如下:
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 newsDetail FROM tbl_NewsDetail WHERE newsId="+ Convert.ToInt32(Request.QueryString["NewsId"]);
   HtmlTableCell cellNewsDetail = new HtmlTableCell();
   SqlCommand myComd = new SqlCommand(strSql,myCon);
   SqlDataReader sqlRdr;   
   try
   {
    myCon.Open();
    sqlRdr = myComd.ExecuteReader();
    if (sqlRdr.Read())
    {
     cellNewsDetail.InnerText = sqlRdr.GetValue(0).ToString();
     rowNewsDetail.Cells.Add(cellNewsDetail);
    }
    else
    {
     Response.Write("No Record found in the detail table");
    }
    sqlRdr.Close();
   }
   catch(Exception msg)
   {
    Response.Write(msg.Message);
   }
   finally
   {
    //close connection
    myCon.Close();
   }
  }
        3、最后,再新建一个页面,把控件拖放进去,然后以其为初始页面,查看其效果就能看到一个新闻滚动窗口的效果了!
所引用的原文,里面代码可以到这里下载!

 

 

 


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
实现人脸识别功能,可以使用微软提供的 Cognitive Services 中的 Face API。以下是基于 ASP.NET 使用 C# 实现简单人脸识别功能的步骤: 1. 首先,在 Azure 门户网站上创建一个 Cognitive Services 的资源,并在该资源中启用 Face API 服务。 2. 在 Visual Studio 中创建一个 ASP.NET Web 应用程序,并在项目中添加 Microsoft.Azure.CognitiveServices.Vision.Face 包。 3. 在 ASP.NET 项目中添加一个 Web 表单,并添加一个上传图片的控件,例如 FileUpload 控件。 4. 在代码中编写上传图片的逻辑,将上传的图片保存到服务器上。 5. 编写识别人脸的逻辑,并调用 Face API 服务进行人脸识别。以下是示例代码: ```csharp // 获取 Face API 的密钥和终结点 string faceApiKey = ConfigurationManager.AppSettings["FaceApiKey"]; string faceApiEndpoint = ConfigurationManager.AppSettings["FaceApiEndpoint"]; // 创建 Face API 客户端 FaceClient faceClient = new FaceClient(new ApiKeyServiceClientCredentials(faceApiKey)) { Endpoint = faceApiEndpoint }; // 读取上传的图片并进行人脸识别 using (Stream imageStream = File.OpenRead(Server.MapPath("~/uploads/" + fileName))) { // 调用 Face API 进行人脸识别 IList<DetectedFace> faces = await faceClient.Face.DetectWithStreamAsync(imageStream, true, true); // 输出识别结果 foreach (var face in faces) { Response.Write("Face ID: " + face.FaceId + "<br/>"); Response.Write("Gender: " + face.FaceAttributes.Gender + "<br/>"); Response.Write("Age: " + face.FaceAttributes.Age + "<br/>"); Response.Write("Smile: " + face.FaceAttributes.Smile + "<br/>"); } } ``` 以上就是基于 ASP.NET 使用 C# 实现简单人脸识别功能的步骤。需要注意的是,为了保护用户的隐私,应该对上传的图片进行适当的处理,如删除或加密。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值