DataView Filter : DataView « ADO.net Database « ASP.NET Tutorial

ASP.NET Tutorial
1. ASP.Net Instroduction
2. Language Basics
3. ASP.net Controls
4. HTML Controls
5. Page Lifecycle
6. Response
7. Collections
8. Validation
9. Development
10. File Directory
11. Sessions
12. Cookie
13. Cache
14. Custom Controls
15. Profile
16. Configuration
17. LINQ
18. ADO.net Database
19. Data Binding
20. Ajax
21. Authentication Authorization
22. I18N
23. Mobile
24. WebPart
25. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.NET Tutorial » ADO.net Database » DataView 
18. 31. 1. DataView Filter
<%@ Page language="c#" Inherits="DataViewFilter" CodeFile="Default.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <body>
    <form method="post" runat="server" ID="Form1">
      <b><u>Filter = "ProductName = 'Chocolade' "</u></b><br>
      <br>
      <asp:GridView runat="server" ID="Datagrid1" HeaderStyle-Font-Bold="true" />
      <br>
      <STRONG><U>Filter = "UnitsInStock = 0 AND UnitsOnOrder = 0" </U></STRONG>
      <br>
      <br>
      <asp:GridView runat="server" ID="Datagrid2" HeaderStyle-Font-Bold="true" />
      <br>
      <STRONG><U>Filter = <STRONG><U>"ProductName LIKE 'P%'"</U></STRONG></U></STRONG><br>
      <br>
      <asp:GridView runat="server" ID="Datagrid3" HeaderStyle-Font-Bold="true" />
    </form>
  </body>
</HTML>

File: Default.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class DataViewFilter : System.Web.UI.Page
{

  protected void Page_Load(object sender, System.EventArgs e)
  {
    string connectionString = "Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI";
    SqlConnection con = new SqlConnection(connectionString);
    string sql = "SELECT ProductID, ProductName, UnitsInStock, UnitsOnOrder, Discontinued FROM Products";

    SqlDataAdapter da = new SqlDataAdapter(sql, con);
    DataSet ds = new DataSet();

    da.Fill(ds, "Products");

    DataView view1 = new DataView(ds.Tables["Products"]);
    view1.RowFilter = "ProductName = 'Chocolade'";
    Datagrid1.DataSource = view1;

    DataView view2 = new DataView(ds.Tables["Products"]);
    view2.RowFilter = "UnitsInStock = 0 AND UnitsOnOrder = 0";
    Datagrid2.DataSource = view2;

    DataView view3 = new DataView(ds.Tables["Products"]);
    view3.RowFilter = "ProductName LIKE 'P%'";
    Datagrid3.DataSource = view3;

    this.DataBind();

  }

}
18. 31. DataView
18. 31. 1. DataView Filter
18. 31. 2. DataView Sort
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.