Blog Content

    티스토리 뷰

    16.ASP.NET - 자료실 게시판(9) : List.aspx

    반응형
    Upload - List.aspx

    List.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="List.aspx.cs" Inherits="Upload_List" %>

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

     

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head id="Head1" runat="server">

        <title>자료실 리스트</title>

    </head>

    <body>

        <form id="form1" runat="server">

       

        <div>

            <asp:GridView ID="ctlUploadList" runat="server"

                AutoGenerateColumns="false" AllowPaging="True"

                PageSize="3" onpageindexchanging="ctlUploadList_PageIndexChanging">

               

                <Columns>

                    <asp:BoundField DataField="Num" HeaderText="번호" />

                    <asp:HyperLinkField DataTextField="Title" HeaderText="제목"

                        DataNavigateUrlFormatString="View.aspx?Num={0}"

                        DataNavigateUrlFields="Num" />

                    <asp:TemplateField HeaderText="파일">

                        <ItemTemplate>

                            <%# Eval("FileName") %></a>

                            /

                            <%# Eval("FileSize") %>

                            /

                            <asp:HyperLink ID="HyperLink2" runat="server"

                                NavigateUrl=

                                      '<%# "Down.aspx?FileName=" + Eval("FileName") %>'>

                                                             

                            <img src="images/ext_zip.GIF" border="0" alt="다운로드" />

                            </asp:HyperLink>               

                            /

                            <%# FuncFileLink(Eval("FileName")) %>

                        </ItemTemplate>                   

                    </asp:TemplateField>               

                </Columns>

               

            </asp:GridView>

                <asp:DropDownList ID="SearchField" runat="server">

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

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

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

            </asp:DropDownList>

           

            <asp:TextBox ID="SearchQuery" 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>

       

        </form>

    </body>

    </html>


    List.aspx.cs

    using System;

     

    public partial class Upload_List : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            if (!Page.IsPostBack)

            {

                DisplayData();

            }

        }

     

        private void DisplayData()

        {

            UploadBiz ub = new UploadBiz();

            this.ctlUploadList.DataSource = ub.ListUpload();

            this.ctlUploadList.DataBind();

        }

     

        protected void btnSearch_Click(object sender, EventArgs e)

        {

            Response.Redirect(

                String.Format(

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

                    , SearchField.SelectedValue

                    , SearchQuery.Text));

        }

     

        protected void btnWrite_Click(object sender, EventArgs e)

        {

            Response.Redirect("Write.aspx"); // 글쓰기 페이지로 이동

        }

     

        // 코드 비하인드 페이지에서 링크 만들기

        protected string FuncFileLink(object fileName)

        {

            string name = Convert.ToString(fileName);

     

            if (!String.IsNullOrEmpty(name))

            {

                return "<a href='Down.aspx?FileName=" + name + "'>다운</a>";

            }

            else

            {

                return "-"; // 파일이 첨부되지 않았다면,

            }

        }

     

        //페이징 처리

        protected void ctlUploadList_PageIndexChanging(

            object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)

        {

            this.ctlUploadList.PageIndex = e.NewPageIndex;

            DisplayData();

        }

    }


    결과화면

    [그림16-1]



    반응형

    Comments