Data Binding ASP.Net

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="MasterDetailsSinglePage" %>



    Untitled Page


    
    

                      runat="server" 
                  GridLines="None" 
          AutoGenerateColumns="False" 
          DataKeyNames="CategoryID" 
          DataSourceID="sourceCategories" 
          OnRowDataBound="gridMaster_RowDataBound">
        
        
        
        
          
            
            
              
<%# Eval("CategoryName") %>

              
<%# Eval("Description" ) %>

            

          
          
            
            
                                          runat="server" 
                            AutoGenerateColumns="False"
                          BorderStyle="None">
                    
                
                
                  
                  
                  
                  
                
    
              
            

          
        

        
      
                                   runat="server" 
                           ConnectionString="<%$ ConnectionStrings:Northwind %>"
                           ProviderName="System.Data.SqlClient" 
                           SelectCommand="SELECT * FROM Categories"/>
                                   runat="server" 
                           ConnectionString="<%$ ConnectionStrings:Northwind %>"
                           ProviderName="System.Data.SqlClient" 
                           SelectCommand="SELECT * FROM Products WHERE CategoryID=@CategoryID">
            
                
            

        
    

    


File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class MasterDetailsSinglePage : System.Web.UI.Page
{
  protected void gridMaster_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
      GridView gridChild = (GridView)e.Row.Cells[1].Controls[1];
      sourceProducts.SelectParameters[0].DefaultValue = gridMaster.DataKeys[e.Row.DataItemIndex].Value.ToString();
      object data = sourceProducts.Select(DataSourceSelectArguments.Empty);
      
      gridChild.DataSource = data;
      gridChild.DataBind();
    }
  }
}