日期:2014-05-17 浏览次数:20431 次
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always"> <ContentTemplate> <table style="width:100%;"> <tr> <td class="style1Transparent" valign="top"> <%showTitle(); %></td> <td> <% showRss();%></td> </tr> </table> </ContentTemplate> </asp:UpdatePanel>
public void showRss() { ArrayList channel=new ArrayList(); //记录频道的动态数组 string strConnection = "server=localhost;database=rssdata;uid=sa;pwd=''"; //链接数据库的参数字符 SqlConnection sqlcon = new SqlConnection(strConnection); //建立连接 sqlcon.Open(); //打开数据库 //输出所有新闻 // Response.Write("<asp:UpdatePanel ID='UpdatePanel1' runat='server'>"); // Response.Write(" <ContentTemplate>"); Response.Write("<DIV id='Rss_cnt'class='content'>"); Response.Write("<span>"); SqlCommand adsa = new SqlCommand("select * from rss_table", sqlcon); //建立一个sqlcommand对象,要求输出相应的内容 SqlDataReader rdr = adsa.ExecuteReader(); while (rdr.Read()) { Response.Write("<div class='back'>"); if (rdr.GetValue(8).Equals(0)) Response.Write("<input class='unreadbtn' type='image' width='20px' hight='20px' title='标记为已读' src='pic/unread.png' runat='server' value='" + rdr.GetValue(2).ToString() + "' onclick='changeread(this)' /> "); else Response.Write("<input class='readbtn' type='image' width='20px' hight='20px' title='标记为未读' src='pic/read.png' runat='server' value='" + rdr.GetValue(2).ToString() + "' onclick='changeread(this)' /> "); if (rdr.GetValue(7).Equals(0)) Response.Write("<input class='unlikebtn' type='image' width='20px' hight='20px' title='加入喜欢' src='pic/unlike.png' runat='server' value='"+rdr.GetValue(2).ToString()+"' onclick='changelike(this)' /> "); else Response.Write("<input class='likebtn' type='image' width='20px' hight='20px' title='取消喜欢' src='pic/like.png' runat='server' value='" + rdr.GetValue(2).ToString() + "' onclick='changelike(this)' /> "); Response.Write("<a href='" + rdr.GetValue(3) + "' target='_blank'>" + rdr.GetValue(2) + "</a><br/>"); //输出到客户端 Response.Write(rdr.GetValue(5) + "<br/>"); Response.Write(rdr.GetValue(4) + "<br/>"); Response.Write("</div><br/>"); } Response.Write("</span>"); rdr.Close(); //输出最爱新闻 Response.Write("<span>"); adsa = new SqlCommand("select * from rss_table where likeornot=1", sqlcon); //建立一个sqlcommand对象,要求输出相应的内容 rdr = adsa.ExecuteReader(); while (rdr.Read()) {