ADO Net Database ASP.Net Tutorial

File: ShowUIPaging.aspx
<%@ Page Language="C#" %>
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">


    Show User Interface Paging


    
    

            id="grdProducts"
        DataSourceID="srcProducts"
        AllowPaging="true"
        PageSize="3"
        CssClass="products"
        Runat="server" />
            id="srcProducts"
        TypeName="ProductUIPaging"
        SelectMethod="GetProductsDataSet"
        Runat="server" />
    

    


File: ProductUIPaging.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
public class ProductUIPaging
{
    private readonly string _conString;
    public DataSet GetProductsDataSet()
    {
        string commandText = "SELECT Id,Title,Director FROM Products";
        SqlDataAdapter dad = new SqlDataAdapter(commandText, _conString);
        DataSet dstProducts = new DataSet();
        using (dad)
        {
            dad.Fill(dstProducts);
        }
        return dstProducts;
    }
    public ProductUIPaging()
    {
        _conString = WebConfigurationManager.ConnectionStrings["Products"]. ConnectionString;
    }
}
File: Web.config

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