using System.Configuration;
using System.Data;
using System.Data.SqlClient;
public partial class Category_FrmRowfilter : System.Web.UI.Page
{
protected void Page_Load(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");
//전체출력
this.ctlSearchList.DataSource = ds;
this.ctlSearchList.DataBind();
con.Close();
}
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");
//전체출력
this.ctlSearchList.DataSource = ds;
this.ctlSearchList.DataBind();
//[1]DataTable변환
DataTable dt = ds.Tables[0];
//[2]DataView 변환
DataView dv = dt.DefaultView;
//[3]DataView.RowFilter변경
dv.RowFilter = "CategoryName Like '%" + txtSerchquery.Text + "%'";
dv.Sort = "CategoryName Asc"; //정렬
this.ctlSearchList.DataSource = dv;
this.ctlSearchList.DataBind();
con.Close();
}
} |