Blog Content

    티스토리 뷰

    01.ASP.NET - 기본형 게시판(2) : List(리스트) 페이지

    반응형
    List(리스트) 페이지 : 게시물을 보는 페이지 작성

    List.aspx

    <div>

       게시판 리스트<br />

       <br />

       <asp:GridView ID="ctlBasicList" 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:DropDownList ID="lstSearchField" runat="server">

           <asp:ListItem Value="Name">이름</asp:ListItem>

           <asp:ListItem Value="Title" Selected="True">제목</asp:ListItem>

           <asp:ListItem Value="Content">내용</asp:ListItem>

       </asp:DropDownList>

       <asp:TextBox ID="txtSearchQuery" runat="server"></asp:TextBox>

       <asp:Button ID="btnSearch" runat="server" Text="검색"

           onclick="btnSearch_Click" /><br />

       <asp:Button ID="btnWrite" runat="server" Text="글쓰기"

           onclick="btnWrite_Click" />

    </div>


    List.aspx.cs

    private void DisplayData()

    {

       // 커넥션

       SqlConnection con = new SqlConnection(

           ConfigurationManager.ConnectionStrings

           ["ConnectionString"].ConnectionString);

     

       // 커멘드

       SqlCommand cmd = new SqlCommand("ListBasic", con);

       cmd.CommandType = CommandType.StoredProcedure;

     

       // 데이터어뎁터

       SqlDataAdapter da = new SqlDataAdapter(cmd);

     

       // 데이터

       DataSet ds = new DataSet();

     

       // Fill()

       da.Fill(ds, "Basic");

     

       // 바인딩

       this.ctlBasicList.DataSource = ds.Tables[0];

       this.ctlBasicList.DataBind();

    }

     

    protected void btnSearch_Click(object sender, EventArgs e)

    {

       // 검색페이지로 필드명과 검색어 전달

       string strUrl =

           String.Format(

           "Search.aspx?SearchField={0}&SearchQuery={1}"

           , lstSearchField.SelectedValue

           , txtSearchQuery.Text

           );

     

       Response.Redirect(strUrl);

    }

     

    protected void btnWrite_Click(object sender, EventArgs e)

    {

       // 쓰기 페이지로 이동

       Response.Redirect("Write.aspx");

    }


    결과화면

    [그림01-1]



    반응형

    Comments