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] |
'ASP.NET' 카테고리의 다른 글
03.ASP.NET - 기본형 게시판(4) : View(상세보기) 페이지 (2) | 2009.10.07 |
---|---|
02.ASP.NET - 기본형 게시판(3) : Write(글쓰기) 페이지 (2) | 2009.10.07 |
00.ASP.NET - 기본형 게시판(1) : DB설계 (1) | 2009.10.07 |
24.C# ASP.NET - AdRotator 광고컨트롤 [WebStandardControl] (0) | 2009.10.07 |
23.C# ASP.NET - Calendar(달력) [WebStandardControl] (2) | 2009.10.07 |
Comments