using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Demo.Models;

namespace Demo._4_PivotGrid
{
    public partial class _default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void exportButton_Click(object sender, EventArgs e)
        {

            grid.ExportToExcel();

        }

        protected void grid_NeedDataSource(object sender, Telerik.Web.UI.PivotGridNeedDataSourceEventArgs e)
        {

            grid.DataSource = GetData();

        }
  
        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <returns></returns>
        private DataTable GetData()
        {

            var connString = ConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString;
            var tbl = new DataTable();


            using (var conn = new SqlConnection(connString))
            {
                var da = new SqlDataAdapter("SELECT * FROM SalesDetails", conn);
                da.Fill(tbl);
            }

            // Response.Write("Row Count: " + tbl.Rows.Count);

            return tbl;
        
        }
    
    }
}