using System;
using System.Collections;
using System.Configuration;
using System.Data;
sing System.Data.SqlClient;
public partial class Basic_View : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//넘겨져 온 쿼리 스트링 검사
if (String.IsNullOrEmpty(Request["Num"]))
{
Response.Write("잘못된 요청입니다");
Response.End();
}
else
{
if (!Page.IsPostBack)
{
//넘겨져온 번호에 해당하는 글 출력
Display(); //호출
}
}
}
private void Display()
{
SqlConnection con = new SqlConnection
(ConfigurationManager.ConnectionStrings
["ConnectionString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("ViewBasic", con);
cmd.CommandType = CommandType.StoredProcedure;
//파라미터 추가 : List.aspx에서 넘겨온 쿼리 스트링 값
cmd.Parameters.AddWithValue("@Num", Request["Num"]);
//상세보기 :DataReader
SqlDataReader dr = cmd.ExecuteReader();
//바인딩 : 각각의 컨트롤
while (dr.Read())
{
this.lblNum.Text = dr["Num"].ToString();
this.lblName.Text = dr["Name"].ToString();
this.lblEmail.Text = dr["Email"].ToString();
this.lblHomepage.Text = dr["Homepage"].ToString();
this.lblTitle.Text = dr["Title"].ToString();
this.lblPostDate.Text = dr["PostDate"].ToString();
//인코딩에 따른 Content 출력 3가지 방법
string encoding = dr["Encoding"].ToString(); //Text/Html
if (encoding == "Text") //Text이면
{
this.lblContent.Text =
dr["Content"].ToString().Replace("&", "&")
.Replace("<", "lt;")
.Replace(">", ">")
.Replace
("\t"," ")
.Replace("\r\n", "<br />");
}
else if(encoding =="Mixed") //태그는 실행하되, 엔터는 처리
{
this.lblContent.Text =
dr["Content"].ToString().Replace("\r\n", "<br />");
}
else //html로 변환해서 출력
{
this.lblContent.Text = dr["Content"].ToString();
}
this.lblContent.Text = dr["Content"].ToString();
this.lblReadCount.Text = dr["ReadCount"].ToString();
this.lblPostIP.Text = dr["PostIP"].ToString();
}
dr.Close();
con.Close();
}
protected void btnModifty_Click(object sender, EventArgs e)
{
//수정 페이지로 현재 글의 번호 값 넘김
string strUrl = String.Empty;
strUrl = "./Modify.aspx?Num=" + Request["Num"];
Response.Redirect(strUrl);
}
protected void btnDelete_Click(object sender, EventArgs e)
{
//삭제된 페이지로 현재 글의 번호 값 넘김
Response.Redirect(String.Format
("Delete.aspx?Num={0}", Request["Num"]));
}
protected void btnList_Click(object sender, EventArgs e)
{
//리스트 페이지로 이동
Response.Redirect("./List.aspx");
}
} |