정렬, 필터링, 검색, 편집 및 탐색을 위해 데이터 바인딩할 수 있는 DataTable의 사용자 지정 뷰
FrmDataView.aspx |
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> 상품 리스트 출력<br /> <asp:GridView ID="ctlProductList1" runat="server"> </asp:GridView> <asp:GridView ID="ctlProductList2" runat="server"> </asp:GridView> <asp:GridView ID="ctlProductList3" runat="server"> </asp:GridView> </div> </form> </body> </html> |
FrmDataView.aspx.cs |
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DisplayData(); } } private void DisplayData() { SqlConnection con = new SqlConnection( ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); con.Open(); SqlCommand cmd = new SqlCommand("Select * From Products", con); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; DataSet ds = new DataSet(); da.Fill(ds, "Products"); // 출력 this.ctlProductList1.DataSource = ds; //[1] 데이터셋 this.ctlProductList1.DataBind(); DataTable dt = ds.Tables["Products"]; //[2] 데이터테이블 this.ctlProductList2.DataSource = dt; this.ctlProductList2.DataBind(); DataView dv = ds.Tables[0].DefaultView; //[3] 데이터뷰 this.ctlProductList3.DataSource = dv; this.ctlProductList3.DataBind(); con.Close(); } |
결과화면 |
[그림17-1] |
'ASP.NET' 카테고리의 다른 글
19.ADO.NET - RowFilter (0) | 2009.09.28 |
---|---|
18.ADO.NET - DataRow (0) | 2009.09.28 |
16.ADO.NET - DataTable (0) | 2009.09.28 |
15.ADO.NET - DataSet (0) | 2009.09.28 |
14.ADO.NET - Transaction (0) | 2009.09.28 |
Comments