Search.aspx |
<div> <h3>검색 리스트</h3> <asp:GridView ID="ctlSearchList" runat="server"
AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="번호" DataField="Num" />
<asp:HyperLinkField HeaderText="제목"
DataNavigateUrlFields="Num"
DataNavigateUrlFormatString="View.aspx?Num={0}"
DataTextField="Title" ItemStyle-Width="350px" />
<asp:BoundField HeaderText="작성자" DataField="Name" />
<asp:BoundField HeaderText="작성일" DataField="PostDate"
DataFormatString="{0:yyyy-mm-dd}" />
<asp:BoundField HeaderText="조회수" DataField="ReadCount" /> </Columns> </asp:GridView> <asp:Button ID="btnList" runat="server" Text="검색 종료"
onclick="btnList_Click" /> </div> |
Search.aspx.cs |
protected void Page_Load(object
sender, EventArgs
e) {
if (!Page.IsPostBack)
{
DisplayData(); // 그리드뷰 컨트롤에 데이터 출력
} } private void DisplayData() {
SqlConnection con = new SqlConnection(
ConfigurationManager.ConnectionStrings
["ConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("SearchBasic", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@SearchField"
, Request["SearchField"]); //Name, title
cmd.Parameters.AddWithValue("@SearchQuery"
, Request["SearchQuery"]);
//홍길동, 안녕
SqlDataAdapter
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Basic");
this.ctlSearchList.DataSource
= ds.Tables[0];
this.ctlSearchList.DataBind(); } protected void btnList_Click(object sender, EventArgs
e) {
Response.Redirect("List.aspx"); } |
결과화면 |
[그림6-1] |
'ASP.NET' 카테고리의 다른 글
25.C# ASP.NET - Xml 컨트롤 [WebStandardControl] (0) | 2009.10.08 |
---|---|
07.ASP.NET - 기본형 게시판(8) : 완성 (0) | 2009.10.07 |
05.ASP.NET - 기본형 게시판(6) : 수정(Modify) 페이지 (0) | 2009.10.07 |
04.ASP.NET - 기본형 게시판(5) : Delete(삭제) 페이지 (0) | 2009.10.07 |
03.ASP.NET - 기본형 게시판(4) : View(상세보기) 페이지 (2) | 2009.10.07 |
Comments