ADO Database ASP.Net

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

  void lstCategories_SelectedIndexChanged(Object sender, EventArgs e)  
  {
      SqlDataSource productsSource = new SqlDataSource();
      productsSource.ID = "productsSource";
      Page.Controls.Add(productsSource);
      productsSource.ConnectionString = WebConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString;
      productsSource.SelectCommand = "GetProductsByCategoryID";
      productsSource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
      ControlParameter categoryIdParam = new ControlParameter();
      categoryIdParam.ControlID = "lstCategories";
      categoryIdParam.Name = "ProductSubcategoryID";
      categoryIdParam.PropertyName = "SelectedValue";
      productsSource.SelectParameters.Clear();
      productsSource.SelectParameters.Add(categoryIdParam);      
      productsSource.Select(DataSourceSelectArguments.Empty);
      GridView1.DataSource = productsSource;
      GridView1.DataBind();                  
  }



    Programmatically adding a SqlDataSource control to the Page


    
    

                    ProviderName="System.Data.SqlClient"
            ConnectionString="<%$ ConnectionStrings:AdventureWorks %>"
            SelectCommand="GetProductSubCategories" 
            SelectCommandType="StoredProcedure">            
        
        Categories: 
                    DataSourceID="categoriesSource"
            DataValueField="ProductSubcategoryID" 
            OnSelectedIndexChanged="lstCategories_SelectedIndexChanged"
            DataTextField="Name" 
            AutoPostBack="true" 
            ID="lstCategories" />   
                    HeaderStyle-HorizontalAlign="Center" 
            HeaderStyle-Font-Bold="True"
            HeaderStyle-BackColor="blue" 
            HeaderStyle-ForeColor="White" />