블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

Category

Recent Post

Recent Comment

Archive

2009. 11. 2. 14:13 .Net Project/ASP.NET 3.5 Sp1
반응형
 List.aspx



 
<!-- BoardList.aspx -->
<%@ Page Language="C#" AutoEventWireup="true"
         CodeFile="BoardList.aspx.cs"
         Inherits="DotNetNote_BoardList" %>

<!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 runat="server">
  <title>글 목록</title>
  <link href="../DotNetNote/DotNetNote.css"
    rel="stylesheet" type="text/css" />
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <h3>완성형 게시판</h3>
      <font face="굴림"><font style="font-size: 9pt;
        color: #ff0000">글&nbsp;목록 -&nbsp;완성형
        게시판입니다.</font>
        <hr width="100%" size="1" />
        <p align="center">
      </font>
      <div align="center">
        <table border="0" cellpadding="0"
          cellspacing="0">
          <tr>
            <td>
              <asp:GridView ID="ctlBoardList"
                runat="server" AutoGenerateColumns="False"
                CellPadding="4" ForeColor="#333333"
                GridLines="None" OnRowCreated="ctlBoardList_RowCreated"
                AllowPaging="True" DataKeyNames="Num"
                OnPageIndexChanging="ctlBoardList_PageIndexChanging"
                PageSize="10">
                <FooterStyle BackColor="#5D7B9D"
                  Font-Bold="True" ForeColor="White" />
                <Columns>
                  <asp:TemplateField HeaderText="번호">
                    <ItemTemplate>
                      <%#intTotalCount - ((Container.DataItemIndex))%>
                    </ItemTemplate>
                    <HeaderStyle HorizontalAlign="Center"
                      Width="30px" />
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="제 목">
                    <ItemTemplate>
                      <%#FuncStep(Eval("Step"))%>
                      <asp:HyperLink ID="linkTitle" runat="server"
                        NavigateUrl='<%#FuncLink(Eval("Num"))%>'
                        Text='<%#FuncCutString(Eval("Title"), 30)%>'>
                      </asp:HyperLink>
                      <%#FuncNew(Eval("PostDate"))%>
                    </ItemTemplate>
                    <HeaderStyle Width="350px" />
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="파일">
                    <ItemTemplate>
                      <%#FuncFileDown(Convert.ToInt32(
                        Eval("Num").ToString())
                    , Eval("FileName").ToString()
                    , Eval("FileSize").ToString())%>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Center" />
                    <HeaderStyle HorizontalAlign="Center" />
                  </asp:TemplateField>
                  <asp:BoundField DataField="Name"
                    HeaderText="작성자">
                    <HeaderStyle HorizontalAlign="Center"
                      Width="60px" />
                  </asp:BoundField>
                  <asp:BoundField DataField="PostDate"
                    HeaderText="작성일" DataFormatString="{0:yyyy-MM-dd}"
                    HtmlEncode="False">
                    <HeaderStyle HorizontalAlign="Center"
                      Width="70px" />
                  </asp:BoundField>
                  <asp:BoundField DataField="ReadCount"
                    HeaderText="조회수">
                    <ItemStyle HorizontalAlign="Right" />
                    <HeaderStyle HorizontalAlign="Center"
                      Width="50px" />
                  </asp:BoundField>
                </Columns>
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <EditRowStyle BackColor="#999999" />
                <SelectedRowStyle BackColor="#E2DED6"
                  Font-Bold="True" ForeColor="#333333" />
                <PagerStyle BackColor="#8080FF"
                  ForeColor="White" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#5D7B9D"
                  Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White"
                  ForeColor="#284775" />
                <PagerSettings Mode="NumericFirstLast" />
              </asp:GridView>
            </td>
          </tr>
          <tr>
            <td>
              <table border="0" width="100%"
                cellpadding="3" cellspacing="0">
                <tr>
                  <td width="25%">&nbsp;</td>
                  <td width="50%" align="center">
                    <font face="굴림"></font>
                  </td>
                  <td width="25%" align="right">
                    <asp:Button ID="btnWrite" runat="server"
                      BorderStyle="Groove" BorderWidth="1px"
                      BorderColor="#404040" Text="글쓰기"
                      CausesValidation="False"
                      OnClick="btnWrite_Click">
                    </asp:Button>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </div>
      <p align="center">
        <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>&nbsp;
        <asp:TextBox ID="SearchQuery" runat="server"
          BorderStyle="Solid" BorderWidth="1px"
          Height="21px" Width="200px"></asp:TextBox>&nbsp;
        <asp:Button ID="btnSearch" runat="server"
          BorderStyle="Solid" BorderWidth="1px"
          Text="검 색" OnClick="btnSearch_Click">
        </asp:Button></p>
      <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
        runat="server" ControlToValidate="SearchField"
        Display="None" ErrorMessage="검색할 단어를 입력하세요.">
      </asp:RequiredFieldValidator>
      <asp:ValidationSummary ID="ValidationSummary1"
        runat="server" ShowSummary="False"
        ShowMessageBox="True"></asp:ValidationSummary>
    </div>
  </form>
</body>
</html>


 List.aspx.Cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;

/// <summary>
/// BoardList : 완성형(DotNetNote) 게시판의 리스트 페이지
/// </summary>
public partial class DotNetNote_BoardList : System.Web.UI.Page
{
  #region Private/Protected/Public Member Variables
  public int intPage = 0; // 현재 보여줄 페이지 번호
  public int intTotalCount = 0;//총 레코드 갯수(글번호 순서 정렬용)
  #endregion

  #region Event Handlers
  protected void Page_Load(object sender, System.EventArgs e)
  {
    //쿠키를 사용한 리스트 페이지 번호 유지 적용
    if (Request.Cookies["DotNetNote"] != null)
    {
      if (!String.IsNullOrEmpty(
        Request.Cookies["DotNetNote"]["PageNum"]))
      {
        intPage = Convert.ToInt32(
          Request.Cookies["DotNetNote"]["PageNum"]);
      }
      else
      {
        intPage = 0;
      }
      this.ctlBoardList.PageIndex = intPage;
    }

    intTotalCount = GetTotalRecordCount();//DotNetNote테이블의 총 데이터 수

    if (!Page.IsPostBack)
    {
      ReadData();
    }
  }

  #region 글쓰기 페이지로 이동
  protected void btnWrite_Click(object sender, System.EventArgs e)
  {
    Response.Redirect("./BoardWrite.aspx");
  }
  #endregion

  #region 검색 처리 링크
  protected void btnSearch_Click(object sender, System.EventArgs e)
  {
    string strQuery =
      String.Format(
      "./BoardSearch.aspx?SearchField={0}&SearchQuery={1}",
      SearchField.SelectedItem.Value,
      SearchQuery.Text
      );
    Response.Redirect(strQuery);
  }
  #endregion

  #region 마우스 오버 효과
  protected void ctlBoardList_RowCreated(
    object sender, GridViewRowEventArgs e)
  {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
      e.Row.Attributes["onmouseover"] =
        "this.style.backgroundColor ='#FFE9BB'";
      e.Row.Attributes["onmouseout"] =
        "this.style.backgroundColor=''";
    }
  }
  #endregion

  #region 페이지 이동 링크 기능 구현
  protected void ctlBoardList_PageIndexChanging(
object sender, GridViewPageEventArgs e)
  {
    intPage = e.NewPageIndex;
    ctlBoardList.PageIndex = e.NewPageIndex;
    Response.Cookies["DotNetNote"]["PageNum"] =
      intPage.ToString();//페이지 번호 유지
    ReadData();
  }
  #endregion
  #endregion

  #region Public Methods
  #region 현재 게시판 테이블의 레코드의 수를 반환하는 메서드
  private int GetTotalRecordCount()
  {
    SqlConnection objCon = new SqlConnection();
    objCon.ConnectionString =
      ConfigurationManager.ConnectionStrings[
        "ConnectionString"].ConnectionString;
    objCon.Open();

    SqlCommand objCmd = new SqlCommand();
    objCmd.Connection = objCon;
    objCmd.CommandText = "GetCountDotNetNote";
    objCmd.CommandType = CommandType.StoredProcedure;
    int totalCount = (int)objCmd.ExecuteScalar();
    objCon.Close();

    return totalCount;
  }
  #endregion

  #region 출력상세 페이지 이동 링크
  public string FuncLink(object objNum)
  {
    return String.Format(
      "BoardView.aspx?Num={0}", objNum.ToString());
  }
  #endregion

  #region 각 글의 Step별 들여쓰기 처리
  public string FuncStep(object objStep)
  {
    int intStep = Convert.ToInt32(objStep);
    string strTemp = String.Empty;
    if (intStep == 0)
    {
      strTemp = String.Empty;
    }
    else
    {
      for (int i = 0; i < intStep; i++)
      {
        strTemp =
          String.Format(
          "<img src={0} height={1} width={2}>",
          "images/blank.gif",
          "0",
          (intStep * 15)
          );
      }
      strTemp += "<img src='images/re.gif'>";
    }
    return strTemp;
  }
  #endregion

  #region 제목 길이 자르기
  public static string FuncCutString(
    object strTitle, int intMax)
  {
    return RedPlus.Library.Board.CutString(
      strTitle.ToString(), intMax);
  }
  #endregion

  #region 파일 다운로드 기능
  public string FuncFileDown(
    int intNum, string strFileName, string strFileSize)
  {
    if (strFileName.Length > 0)
    {
      return "<a href='BoardDown.aspx?Num=" + intNum.ToString()
        + "'>" + RedPlus.Library.Board.DownloadType(
          strFileName, strFileName + "("
            + RedPlus.Library.Board.ConvertToFileSize(
              Convert.ToInt32(strFileSize)) + ")") + "</a>";
    }
    else
    {
      return "-";
    }
  }
  #endregion
 
  #region 24시간내에 올라온 글 new 이미지 표시하기
  public string FuncNew(object strDate)
  {
    DateTime originDate = Convert.ToDateTime(strDate);

    TimeSpan objTs = DateTime.Now - originDate;
    Literal l = new Literal();
    if (objTs.TotalMinutes < 1440)
    {
      l.Text = "<img src=images/new.gif>";
    }
    return l.Text;
  }
  #endregion

  #region 현재 페이지에 해당하는 데이터 읽어서 그리드뷰에 출력
  private void ReadData()
  {
    SqlConnection objCon = new SqlConnection(
      ConfigurationManager.ConnectionStrings[
        "ConnectionString"].ConnectionString);
    objCon.Open();

    SqlCommand objCmd = new SqlCommand("ListDotNetNote", objCon);
    objCmd.CommandType = CommandType.StoredProcedure;

    SqlDataAdapter objDa = new SqlDataAdapter();
    objDa.SelectCommand = objCmd;

    DataSet objDs = new DataSet();
    objDa.Fill(objDs, "DotNetNote");

    this.ctlBoardList.DataSource =
      objDs.Tables["DotNetNote"].DefaultView;
    this.ctlBoardList.DataBind();
  }

  #endregion
  #endregion
}






반응형
posted by Magic_kit