您的位置:首页 > 编程语言 > ASP

ASP·NET头条新闻显示功能详解

2011-10-22 10:01 316 查看
运行效果:



前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TopNews222.aspx.cs" Inherits="web.TopNews222" %>

<!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>头条新闻</title>

<!-- 图片滚动 -->

<SCRIPT language="javascript">

var nn;

nn=2;

setTimeout('change_img()',4000);

function change_img()

{

if(nn>5) nn=1

setTimeout('setFocus1('+nn+')',4000);

nn++;

tt=setTimeout('change_img()',4000);

}

function setFocus1(i)

{

selectLayer1(i);

}

function selectLayer1(i)

{

switch(i)

{

case 1:

document.getElementById("focusPic1").style.display="block";

document.getElementById("focusPic2").style.display="none";

document.getElementById("focusPic3").style.display="none";

document.getElementById("focusPic4").style.display="none";

document.getElementById("focusPic5").style.display="none";

break;

case 2:

document.getElementById("focusPic1").style.display="none";

document.getElementById("focusPic2").style.display="block";

document.getElementById("focusPic3").style.display="none";

document.getElementById("focusPic4").style.display="none";

document.getElementById("focusPic5").style.display="none";

break;

case 3:

document.getElementById("focusPic1").style.display="none";

document.getElementById("focusPic2").style.display="none";

document.getElementById("focusPic3").style.display="block";

document.getElementById("focusPic4").style.display="none";

document.getElementById("focusPic5").style.display="none";

break;

case 4:

document.getElementById("focusPic1").style.display="none";

document.getElementById("focusPic2").style.display="none";

document.getElementById("focusPic3").style.display="none";

document.getElementById("focusPic4").style.display="block";

document.getElementById("focusPic5").style.display="none";

break;

case 5:

document.getElementById("focusPic1").style.display="none";

document.getElementById("focusPic2").style.display="none";

document.getElementById("focusPic3").style.display="none";

document.getElementById("focusPic4").style.display="none";

document.getElementById("focusPic5").style.display="block";

break;

}

}

</SCRIPT>

</head>

<body>

<table style="BORDER-RIGHT: #9ec9eb 1px solid; BORDER-TOP: #9ec9eb 1px solid; BORDER-LEFT: #9ec9eb 1px solid; BORDER-BOTTOM: #9ec9eb 1px solid"

height="434" width="611">

<tr>

<td>

<DIV id="ImgChangeMain">

<DIV id="focusPic1" style="DISPLAY: block"><A href="TopNews.aspx?TopId=1" target="_blank"><IMG height="369" src="topImg/1.jpg" width="611" border="0"></A>

<TABLE style="CLEAR: both; MARGIN: auto" cellSpacing="1" cellPadding="0" width="98%" align="right"

border="0">

<TBODY>

<TR align="center" bgColor="#9ec9ec">

<TD bgColor="#e2eaf7"> </TD>

<TD style="COLOR: #ffffff" width="26" bgColor="#0049a5">1</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(2)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">2</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(3)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">3</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(4)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">4</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(5)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">5</TD>

</TR>

</TBODY>

</TABLE>

</DIV>

<DIV class="ImgChange1" id="focusPic2" style="DISPLAY: none"><A href="TopNews.aspx?TopId=2" target="_blank"><IMG height="369" src="topImg/2.jpg" width="611" border="0"></A>

<TABLE style="CLEAR: both; MARGIN: auto" cellSpacing="1" cellPadding="0" width="98%" align="right"

border="0">

<TBODY>

<TR align="center" bgColor="#9ec9ec">

<TD bgColor="#e2eaf7"> </TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(1)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">1</TD>

<TD style="COLOR: #ffffff" width="26" bgColor="#0049a5">2</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(3)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">3</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(4)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">4</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(5)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">5</TD>

</TR>

</TBODY>

</TABLE>

</DIV>

<DIV class="ImgChange1" id="focusPic3" style="DISPLAY: none"><A href="TopNews.aspx?TopId=3" target="_blank"><IMG height="369" src="topImg/3.jpg" width="611" border="0"></A>

<TABLE style="CLEAR: both; MARGIN: auto" cellSpacing="1" cellPadding="0" width="98%" align="right"

border="0">

<TBODY>

<TR align="center" bgColor="#9ec9ec">

<TD bgColor="#e2eaf7"> </TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(1)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">1</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(2)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">2</TD>

<TD style="COLOR: #ffffff" width="26" bgColor="#0049a5">3</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(4)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">4</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(5)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">5</TD>

</TR>

</TBODY>

</TABLE>

</DIV>

<DIV class="ImgChange1" id="focusPic4" style="DISPLAY: none"><A href="TopNews.aspx?TopId=4" target="_blank"><IMG height="369" src="topImg/4.jpg" width="611" border="0"></A>

<TABLE style="CLEAR: both; MARGIN: auto" cellSpacing="1" cellPadding="0" width="98%" align="right"

border="0">

<TBODY>

<TR align="center" bgColor="#9ec9ec">

<TD bgColor="#e2eaf7"> </TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(1)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">1</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(2)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">2</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(3)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">3</TD>

<TD style="COLOR: #ffffff" width="26" bgColor="#0049a5">4</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(5)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">5</TD>

</TR>

</TBODY>

</TABLE>

</DIV>

<DIV class="ImgChange1" id="focusPic5" style="DISPLAY: none"><A href="TopNews.aspx?TopId=5" target="_blank"><IMG height="369" src="topImg/5.jpg" width="611" border="0"></A>

<TABLE style="CLEAR: both; MARGIN: auto" cellSpacing="1" cellPadding="0" width="98%" align="right"

border="0">

<TBODY>

<TR align="center" bgColor="#9ec9ec">

<TD bgColor="#e2eaf7"> </TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(1)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">1</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(2)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">2</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(3)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">3</TD>

<TD onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" style="CURSOR: pointer"

onclick="javascript:setFocus1(4)" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'"

width="26" bgColor="#9ec9ec">4</TD>

<TD style="COLOR: #ffffff" width="26" bgColor="#0049a5">5</TD>

</TR>

</TBODY>

</TABLE>

</DIV>

</DIV> <!--ImgChangeMain End--></td>

</tr>

</table>

<form id="form1" runat="server">

<div>

</div>

</form>

</body>

</html>

TopNews.aspx前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TopNews.aspx.cs" Inherits="fashionArea_TopNews" %>

<!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>头条新闻</title>

</head>

<body>

<form id="form1" runat="server">

<table width="865" height="211" align="center" cellpadding="0" cellspacing="0" style="border-right: #9ec9eb 1px solid;

border-top: #9ec9eb 1px solid; border-left: #9ec9eb 1px solid; padding-top: 4px;

border-bottom: #9ec9eb 1px solid">

<tr>

<td height="10" width="760">

</td>

</tr>

<tr>

<td id="Title" runat="server" align="center" height="30" style="font-weight: bold; font-size: larger">

</td>

</tr>

<tr>

<td id="newContent" runat="server" style="padding-right: 10px; padding-left: 10px; height: 26px; text-indent: 2em;">

</td>

</tr>

</table>

</form>

</body>

</html>

TopNews.aspx后台代码:

protected void Page_Load(object sender, EventArgs e)

{

string TopId = Request.QueryString["TopId"];

SqlConnection conn = new SqlConnection("Data Source=.;User ID=sa;Password=123;Initial Catalog=kxjm_DB");

conn.Open();

SqlCommand command = new SqlCommand("select * from news where id='" + TopId + "'", conn);

SqlDataReader reader = command.ExecuteReader();

while (reader.Read())

{

Title.InnerText = reader[1].ToString();

newContent.InnerHtml = reader[2].ToString();

}

conn.Close();

command.Dispose();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: