📄 article.ascx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Article : System.Web.UI.UserControl
{
string VirtualPath = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
openDataBase_and_BindToDataGrid();
}
}
//翻页
protected void changepage(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
{
if (e.NewPageIndex >= 0)
{
this.GridView1.PageIndex = e.NewPageIndex;
openDataBase_and_BindToDataGrid();
}
}
private void openDataBase_and_BindToDataGrid()
{
DataSet ds = new DataSet();
DAL.boBusiness bo = new DAL.boBusiness();
DAL.MakeConnection Conn = new DAL.MakeConnection();
DAL.clsDBConnkey ConnKey = new DAL.clsDBConnkey();
ConnKey = bo.loadkey();//得到config数据库连接
string sql = "select ID,Title,Content,CreateTime,Summary,IsNominate,ReadTotal,(select count(*) from MessageBoard where MessageBoard.ArticleID=Article.ID )as MessageNum from Article where Article.IsNominate=1 order by CreateTime desc ";
try
{
if (sql != "")
{
ds = (DataSet)Conn.MakeConnectionMethod(sql, ConnKey, DAL.executeMethod.execute_DataSet, DAL.
EnumDBType.Sql, VirtualPath);
if (ds.Tables[0].Rows.Count > 0)
{
DataTable dt = ds.Tables[0];
dt.Columns.Add(new DataColumn("HTML", typeof(string)));
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
if (dt.Rows[i][j] == null || dt.Rows[i][j].ToString() == "")
{
dt.Rows[i][j] = DBNull.Value;
}
}
dt.Rows[i]["HTML"] = MakeHTML(dt.Rows[i]);
}
if (this.GridView1.PageIndex > 0)
{
int intPageCount = (dt.Rows.Count / this.GridView1.PageSize) + (dt.Rows.Count % this.GridView1.PageSize != 0 ? 1 : 0);
if (intPageCount <= this.GridView1.PageIndex)
{ this.GridView1.PageIndex = 0; }
}
this.GridView1.DataSource = dt.DefaultView;
this.GridView1.DataBind();
}
}
}
catch (System.Exception ex)
{
throw ex;
}
}
/// <summary>
/// </summary>
/// <param name="row"></param>
/// <returns></returns>
public static string MakeHTML(System.Data.DataRow row)
{
string messageNum = row["MessageNum"].ToString();
string readNum = row["ReadTotal"].ToString();
string content = row["Content"].ToString();
string summary = row["Summary"].ToString();
string title = row["Title"].ToString();
string createTime = row["CreateTime"].ToString();
string ID = row["ID"].ToString();
string HTML = "";
HTML += "<table width=600 height=101 border=0 cellpadding=0 cellspacing=0>";
HTML += "<tr>";
HTML += "<th height=23 align=left background=image/artTitleBackImage1.gif scope=col> <a href=Content.aspx?ID=" + ID + ">" + title + "</a> <a href=WebPage/MakeRss.aspx?ID=" + ID + ">(RSS)</a></th>";
HTML += "</tr>";
HTML += "<tr>";
HTML += "<td height=13 align=right>" + createTime + "</a></td>";
HTML += "</tr>";
HTML += "<tr>";
HTML += "<td height=10></td>";
HTML += "</tr>";
HTML += "<tr>";
HTML += "<td valign=center><a href=Content.aspx?ID=" + ID + ">" + summary + "</td>";
HTML += "</tr>";
HTML += "<tr>";
HTML += "<td height=10></td>";
HTML += "</tr>";
HTML += "<tr>";
HTML += "<td height=6 align=right>评论(" + messageNum + ") | 阅读次数(" + readNum + ")</td>";
HTML += "</tr>";
HTML += "<tr>";
HTML += "<td height=7 align=right> </td>";
HTML += "</tr>";
HTML += "</table>";
return HTML;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -