1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11 using System.Data.SqlClient;//
12
13 public partial class Basic_Search : System.Web.UI.Page
14 {
15 protected void Page_Load(object sender, EventArgs e)
16 {
17 if (Page.PreviousPage != null) // 이전 페이지가 있다면,
18 {
19 // 현재 페이지에서 계속 살아있는 변수 : ViewState개체
20 ViewState["strSearchField"] =
21 ((DropDownList)Page.PreviousPage.FindControl(
22 "lstSearchField")).SelectedValue; //Name,Title,Content
23 ViewState["strSearchQuery"] =
24 ((TextBox)Page.PreviousPage.FindControl(
25 "txtSearchQuery")).Text;//검색어
26 DisplayData(); // 넘겨져 온 검색 결과 출력 메서드
27 }
28 }
29 private void DisplayData()
30 {
31 //[1] 변수 선언부
32 string strSql = "SearchBasic";//저장프로시저
33 #region Con+Cmd
34 //[2] 커넥션
35 SqlConnection objCon = new SqlConnection();
36 objCon.ConnectionString =
37 ConfigurationManager.ConnectionStrings[
38 "ConnectionString"].ConnectionString;//web.config접근
39 objCon.Open();
40 //[3] 커멘드
41 SqlCommand objCmd = new SqlCommand();
42 objCmd.Connection = objCon;
43 objCmd.CommandText = strSql;
44 objCmd.CommandType = CommandType.StoredProcedure;//*
45 #endregion
46 //[!] 파라미터 추가
47 objCmd.Parameters.AddWithValue(
48 "@SearchField", ViewState["strSearchField"]);
49 objCmd.Parameters.AddWithValue(
50 "@SearchQuery", ViewState["strSearchQuery"]);
51 //[4] 데이터어댑터
52 SqlDataAdapter objDa = new SqlDataAdapter();
53 objDa.SelectCommand = objCmd;//커멘드 개체 지정
54 //[5] 데이터셋
55 DataSet objDs = new DataSet();
56 objDa.Fill(objDs, "Basic");//어댑터의Fill메서드로데이터셋담기
57 //[6] 그리드뷰
58 this.ctlSearchList.DataSource = objDs;//데이터원본지정
59 this.ctlSearchList.DataBind();//출력
60 //[7] 마무리
61 objCon.Close();
62 }
63 protected void btnEnd_Click(object sender, EventArgs e)
64 {
65 Response.Redirect("List.aspx");//리스트로 이동
66 }
67 protected void ctlSearchList_PageIndexChanging(
68 object sender, GridViewPageEventArgs e)
69 {
70 this.ctlSearchList.PageIndex = e.NewPageIndex;
71 DisplayData();
72 }
73 }
74