实例介绍
【实例简介】
【实例截图】
【实例截图】
【核心代码】
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
public partial class BlogIndex : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlForm Form1;
SqlConnection ST_myConn;
public string ST_bgcolor;
protected System.Web.UI.WebControls.Calendar Calendar1;
public string ST_tcolor;
protected void Page_Load(object sender, EventArgs e)
{
// 在此处放置用户代码以初始化页面
string ST_dns = ConfigurationSettings.AppSettings["conStr"];
//最新推荐文章
string ST_cmd_sql = "select top 10 * from ST_news where ST_n_iscmd=1 order by ST_n_date desc";
ST_myConn = new SqlConnection(ST_dns);
SqlDataAdapter ST_classCmd = new SqlDataAdapter("select ST_c_id, ST_c_name from ST_class ", ST_myConn);
SqlDataAdapter ST_cmdCmd = new SqlDataAdapter(ST_cmd_sql,ST_myConn);
DataSet ST_classds = new DataSet();
ST_classCmd.Fill(ST_classds,"类别列表");
DataSet ST_cmdds = new DataSet();
ST_cmdCmd.Fill(ST_cmdds,"推荐文章");
ClassList.DataSource = new DataView(ST_classds.Tables[0]);
ClassList.DataBind();
CmdList.DataSource = new DataView(ST_cmdds.Tables[0]);
CmdList.DataBind();
//调用自定义NewsBlogList_Bind方法
NewsBlogList_Bind();
if (Request.Cookies["colors"]!=null)
{
string ST_test = Request.Cookies["colors"].Value;
String[] ST_colorList = ST_test.Split(new char[] { ',' });
ST_bgcolor = ST_colorList[0];
ST_tcolor = ST_colorList[1];
}
else
{
ST_bgcolor = "#FFDE94";
ST_tcolor = "#efe3ce";
}
Page.DataBind();
}
public void ST_get_Replay()
{
Response.Write ("<table width=100% border=0 cellspacing=0 cellpadding=0>");
SqlCommand ST_myCmd = new SqlCommand("select top 6 * from ST_replay order by ST_r_date desc",ST_myConn);
ST_myConn.Open();
SqlDataReader ST_read = ST_myCmd.ExecuteReader();
while (ST_read.Read())
{
Response.Write ("<tr ><td height=25 bgColor=#f8f8f8><div align=center><font style='FONT-SIZE: 12px' color=red><a href=" ST_read[5].ToString() ".aspx title=" ST_read[3].ToString() ">" ST_read[2].ToString() "</a></font></div></td></tr><tr><td><div align=right><em><font style='FONT-SIZE: 12px'>" ST_read[1].ToString() "评论于" ST_read[4].ToString() "</font></em></div></td></tr>");
}
Response.Write ("</table>");
ST_myConn.Close();
}
public void get_Link()
{
Response.Write ("<table width=100% border=0 cellspacing=0 cellpadding=0>");
SqlCommand ST_myCmd = new SqlCommand("select * from ST_link",ST_myConn);
ST_myConn.Open();
SqlDataReader ST_read = ST_myCmd.ExecuteReader();
while (ST_read.Read())
{
Response.Write ("<tr><td height=20><div align=center><font size=-1 color=red><a href=" ST_read[2].ToString() " target=_blank>" ST_read[1].ToString() "</a></font></div></td></tr>");
}
Response.Write ("</table>");
ST_myConn.Close();
}
public void NewsBlogList_Bind()
{
string ST_sql;
if (Request.QueryString["c_id"]==null)
{
ST_sql = "select * from ST_news order by ST_n_date desc";
}
else
{
if (IsSafe(Request.QueryString["c_id"],2)==true)
{
ST_sql = "select * from ST_news where ST_c_id=" Request.QueryString["c_id"] " order by ST_n_date desc";
}
else
{
ST_sql="";
Response.Write("非法参数");
Response.End();
}
}
SqlDataAdapter ST_myCmd = new SqlDataAdapter(ST_sql,ST_myConn);
DataSet ST_ds = new DataSet();
ST_myCmd.Fill(ST_ds,"文章列表");
NewsList.DataSource = new DataView(ST_ds.Tables[0]);
NewsList.DataBind();
}
public bool IsSafe (string str, int prama)
{
if (prama==1)
{
if (Regex.IsMatch(str,"[0-9]"))
{
return true;
}
else
{
return false;
}
}
else
{
if (str.IndexOf("and")>0 || str.IndexOf("or")>0 || str.IndexOf("'")>0)
{
return false;
}
else
{
return true;
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected void NewsList_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
NewsList.PageIndex = e.NewPageIndex;
NewsBlogList_Bind();
}
}
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论