📄 articledetail.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
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.Data.SqlClient;
namespace WebNews
{
/// <summary>
/// ArticleDetail 的摘要说明。
/// </summary>
public class ArticleDetail : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList DataList1;
int articleId;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
//Response.Write(Session["articleId"]);
DataBindDataList();
}
private void DataBindDataList()
{
//string articleId = Session["articleId"].ToString();
articleId = Convert.ToInt32(Request.QueryString["articleId"].ToString());
SqlConnection con = new SqlConnection();
con.ConnectionString = App_Data.ClassConnection.CONN_STRING;
con.Open();
SqlDataAdapter da=new SqlDataAdapter("select * from articles where articleID="+articleId,con);
DataSet ds=new DataSet();
da.Fill(ds,"articles");
DataList1.DataSource=ds.Tables["articles"];
DataList1.DataBind();
ds.Clear();
con.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataList1.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.DataList1_ItemCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataList1_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
if(e.CommandName == "saveCollection")
{
Response.Write("hello");
SqlConnection con = new SqlConnection();
con.ConnectionString = App_Data.ClassConnection.CONN_STRING;
con.Open();
SqlCommand command=new SqlCommand("select title,link from articles where articleID="+this.articleId,con);
SqlDataReader reader=command.ExecuteReader();
string title = "";
string link = "";
if(reader.Read())
{
title = reader.GetString(0).Trim();
link = reader.GetString(1).Trim();
}
//Response.Redirect("AddCollection.aspx?title="+title+"&link="+link);
Session["title"]="";
Session["link"]="";
Session["title"] = title;
Session["link"] = link;
Response.Redirect("AddCollection.aspx");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -