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 DataGrid_UpdatePanel : System.Web.UI.Page
{
    //Global variables
    protected static string Skin = "";
    private string SQL_Default = @"SELECT CustomerID, CompanyName, ContactName, Address, PostalCode FROM Customers ORDER BY CustomerID";
    protected static string SQL = "";
    protected static string KeyField = "";


    protected void Page_Load(object sender, EventArgs e)
    {
        ScriptManager sm = ScriptManager.GetCurrent(Page);

        //Set defaults
        if (sm.IsInAsyncPostBack == false &&
            Page.IsCallback == false &&
            Page.IsPostBack == false)
        {
            Skin = "Classic";
            SQL = SQL_Default;
            KeyField = "CustomerID";
        }

        //Check defaults
        if (Skin == "") Skin = "Classic";
        if (SQL == "")
        {
            SQL = SQL_Default;
            KeyField = "CustomerID";
        }

        BuildControl();
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        Skin = "GrayScale";
        SQL = @"SELECT OrderID, OrderDate, ShippedDate, ShipAddress, ShipCountry FROM Orders ORDER BY OrderID";
        KeyField = "OrderID";
        BuildControl();
    }


    protected void Button2_Click(object sender, EventArgs e)
    {
        Skin = "WinXP";
        SQL = @"SELECT ProductID, ProductName, QuantityPerUnit, UnitPrice, UnitsInStock FROM Products ORDER BY ProductID";
        KeyField = "ProductID";
        BuildControl();
    }


    private void BuildControl()
    {
        myDataGrid.SkinFolder = "~/DataGrid/Skins/" + Skin;
        myDataGrid.DataSource = DataBase.GetDataTableOleDb(SQL, "~/DataGrid/DataBases/Nwind.mdb");
        myDataGrid.KeyFieldName = KeyField;
        myDataGrid.DataBind();

        myDataGrid.ResetColumnWidths();
        myDataGrid.ResetPageNumber();
        myDataGrid.ResetSelectedRow();
        myDataGrid.ResetScrollbars();
        myDataGrid.ResetSortedColumn();
    }
}