ADO Net Database ASP.Net Tutorial

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Configuration" %>


    protected void btnSearch_Click(object sender, EventArgs e)
    {
        DataTable dtblProducts = (DataTable)Cache["ProductsToFilter"];
        if (dtblProducts == null)
        {
            dtblProducts = GetProductsFromDB();
            Cache["ProductsToFilter"] = dtblProducts;
        }
        string filter = String.Format("Title LIKE '{0}*'", txtTitle.Text);
        DataRow[] rows = dtblProducts.Select(filter, "Title");
        grdProducts.DataSource = rows;
        grdProducts.DataBind();
    }
    private DataTable GetProductsFromDB()
    {
        string connectionString = WebConfigurationManager.ConnectionStrings["Products"].ConnectionString;
        SqlDataAdapter dad = new SqlDataAdapter("SELECT Title, Director FROM Products", connectionString);
        DataTable dtblProducts = new DataTable();
        dad.Fill(dtblProducts);
        return dtblProducts;
    }



    Show DataTable Select


    
    

            id="txtTitle"
        Tooltip="Search"
        Runat="server" />
            id="btnSearch"
        Text="Search"
        Runat="server" OnClick="btnSearch_Click" />
    
            id="grdProducts"
        AutoGenerateColumns="false"
        Runat="server">
        
        
        
            <%# ((DataRow)Container.DataItem)["Title"] %>
        

        
        
        
            <%# ((DataRow)Container.DataItem)["Director"] %>
        

        
        

        
    

    


File: Web.config

  
             connectionString="Data Source=.\SQLEXPRESS;
         AttachDbFilename=|DataDirectory|MyDatabase.mdf;Integrated Security=True;User Instance=True" />