using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.Data.SqlClient;

public partial class Default : System.Web.UI.Page 
{
    private void Page_Load(object sender, EventArgs e)
    {
    }
    
    //object reference
    private DataSet ds;

    private void PopulateObjectReference()
    {
        ds = new DataSet("SqlDataSet");
        SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM [Customers]",
            @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Northwind.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
        sda.Fill(ds);
    }

    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        //populate object refrence only here
        if (ds==null)
        {
            PopulateObjectReference();
            RadGrid1.DataSource = ds;
        }
    }

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        // do not use object reference here it throws an exception
        //string name = ds.DataSetName;
    }

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        //use object reference here
        string name = ds.DataSetName;
    }
}
