using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

public partial class _Default : System.Web.UI.Page 
{
    private bool isExport
    {
        get 
        {
            return (bool?)ViewState["isExport"] ?? false;
        }
        set 
        {
            ViewState["isExport"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridGroupByExpression expression = new GridGroupByExpression();
            GridGroupByField gridGroupByField = new GridGroupByField();
            gridGroupByField = new GridGroupByField();
            gridGroupByField.FieldName = "OrderDate";
            gridGroupByField.HeaderText = "OrderDate";
            gridGroupByField.FormatString = "<strong>{0}</strong>";
            expression.SelectFields.Add(gridGroupByField);
            expression.GroupByFields.Add(gridGroupByField);
            RadGrid1.MasterTableView.GroupByExpressions.Add(expression);
        }
    }

    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        using (DataClassesDataContext dataContext = new DataClassesDataContext())
        {
            RadGrid1.MasterTableView.DataSource = (from t in dataContext.Orders
                                   select t).Take(20).ToList();
        }
    }
    protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {

        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {

        }


        if (e.Item is GridPagerItem)
        {
            GridPagerItem item = e.Item as GridPagerItem;
        }
    }

    protected void chkBox_CheckedChanged(object sender, EventArgs e)
    {
        var chkBox = (CheckBox)sender;
        if (chkBox.Checked)
        {
            //RadAjaxPanel radPanel = (RadAjaxPanel)(chkBox).Parent;
            Panel pnl = (Panel)((chkBox).Parent).FindControl("pnlControls");
            pnl.Visible = true;
        }
        else
        {
            //RadAjaxPanel radPanel = (RadAjaxPanel)(chkBox).Parent;
            Panel pnl = (Panel)((chkBox).Parent).FindControl("pnlControls");
            pnl.Visible = false;
        }
    }
    protected void RadGrid1_SortCommand(object source, GridSortCommandEventArgs e)
    {
        if (!e.Item.OwnerTableView.SortExpressions.ContainsExpression(e.SortExpression))
        {

        }
    }
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
        {
 
        }
    }
}
