asp.net 리피터를 이용한 게시판
<%@ Page Title="" Language="C#" MasterPageFile="~/GP/MasterPage.master" Debug="true"%>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
String sql = "SELECT num,title,UserID,writedate,readcount,depth,refer,pos From GPBoard ORDER BY refer asc, pos";
SqlCommand cmd = new SqlCommand(sql, con);
//cmd.Parameters.AddWithValue("@UserID", Page.User.Identity.Name);
con.Open();
SqlDataReader rd = cmd.ExecuteReader();
Repeater1.DataSource = rd;
Repeater1.DataBind();
rd.Close();
con.Close();
}
protected void btnWrite_Click(object sender, EventArgs e)
{
Response.Redirect("BoardW.aspx?Action=Write");
}
public string SetSpace(int depth)
{
if (depth == 0) return "";
string strSpace = "";
for (int i = 0; i < depth; i++)
{
strSpace += " ";
}
strSpace += "└>";
return strSpace;
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("MMain.aspx");
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="Content1" Runat="Server">
<style type="text/css">
table.type10 {
border-collapse: collapse;
text-align: center;
line-height: 1.5;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
margin: 10px 5px;
}
table.type10 thead th {
width: 50px;
padding: 10px;
font-weight: bold;
vertical-align: top;
color: #fff;
background: #e7708d;
margin: 20px 10px;
}
table.type10 tbody th {
width: 50px;
padding: 10px;
}
table.type10 td {
width: 250px;
padding: 10px;
}
table.type10 .even {
background: #fdf3f5;
}
</style>
<div>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="BoardList.css" />
<p style="text-align:center"> <h5><font size="4"><font color="red">HealthManager Community</font></font></h5></p>
<hr />
<asp:Repeater ID="Repeater1" runat="server" >
<HeaderTemplate>
<table class="type10">
<thead>
<tr style="background-color: #fff" >
<td scope="cols">번호</td>
<td scope="cols">제목</td>
<td scope="cols">아이디</td>
<td scope="cols">작성일</td>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tbody>
<tr style="background-color: #fff" onmouseover="this.style.background='skyblue'" onmouseout="this.style.background='white'"
onClick="location.href='BoardV.aspx?No=<%# Eval("num") %>'">
<td><%# Eval("num") %></td>
<td><%# Eval("title") %></td>
<td><%# Eval("UserID") %></td>
<td><%# Eval("writedate") %></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color: #fff" onmouseover="this.style.background='skyblue'" onmouseout="this.style.background='white'"
onClick="location.href='BoardV.aspx?No=<%# Eval("num") %>'">
<td><%# Eval("num") %></td>
<td><%# Eval("title") %></td>
<td><%# Eval("UserID") %></td>
<td><%# Eval("writedate") %></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyDBConnectionString %>" SelectCommand="SELECT * FROM [GPBoard]"></asp:SqlDataSource>
<asp:SqlDataSource ID="MyDBConnectionString" runat="server" ConnectionString="<%$ ConnectionStrings:MyDBConnectionString %>" SelectCommand="SELECT * FROM [GPBoard]"></asp:SqlDataSource>
<br />
<div class="row">
<div class="col-sm-4 align-center">
<asp:Button ID="btnWrite" runat="server" Text="글쓰기" OnClick="btnWrite_Click" class="btn btn-secondary"/>
</div>
<div class="col-sm-4">
</div>
<div class="col-sm-4 align-right">
<asp:Button ID="Button1" runat="server" Text="메인으로" OnClick="Button1_Click" class="btn btn-primary"/>
</div>
</div>
</div>
</asp:Content>
게시판에 page를 나누려고 하는데요
GridView를 이용하면 쉽게 할 수 있지만 사정으로 리피터를 이용해서 게시판을 만들게 되었습니다.
리피터를 이용해서 페이징과 글의 한 페이지당 글 개수를 정하는 법좀 알려주세요~
아래 코드가 참고가 되시기 바랍니다.
먼저 아래는 마크업 부분입니다.
그리고 아래 코드를 참고해보시기 바랍니다.