데이터 검색시 사용하는 속성 : "CategoryName Like '%컴퓨터%'"
Connection->Command->DataAdapter->DataSet->DataTable->Dataview->Dataview.RowFilger 속성
FrmRowFilter.aspx |
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">
<title></title> </head> <body>
<form id="form1" runat="server">
<div>
카테고리명 :
<asp:TextBox ID="txtSearchQuery" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="검색" onclick="btnSearch_Click" />
<asp:GridView ID="ctlSearchList" runat="server">
</asp:GridView>
<br />
</div>
</form> </body> </html> |
FrmRowFilter.aspx.cs |
protected void btnSearch_Click(object sender, EventArgs
e) {
SqlConnection con = new SqlConnection(
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Select * From Categories",
con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Categories");
//[1] DataTable로 변환
DataTable dt = ds.Tables[0];
//[2] DataView로 변환
DataView dv = dt.DefaultView;
//[3] DataView.RowFilter로 필터링
dv.RowFilter = "CategoryName Like
'%" + txtSearchQuery.Text + "%'";
// 필터링
dv.Sort = "CategoryName
Asc"; // 정렬
this.ctlSearchList.DataSource
= dv; // 필터링된 리스트만 출력됨.
this.ctlSearchList.DataBind();
con.Close(); } |
결과화면 |
[그림19-1] |
'ASP.NET' 카테고리의 다른 글
20.ADO.NET - SqlParamter (0) | 2009.09.29 |
---|---|
-- 주소록 DB사용 (0) | 2009.09.29 |
18.ADO.NET - DataRow (0) | 2009.09.28 |
17.ADO.NET - DataView (0) | 2009.09.28 |
16.ADO.NET - DataTable (0) | 2009.09.28 |
Comments