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

系统 1784 0

运行效果:

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

前台代码:

<%@ 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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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();
}

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


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论