using System;
using System.Data;
using System.Configuration;
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;
using Telerik.Web.UI;
using System.Reflection;

public partial class _Default : System.Web.UI.Page
{
    public RadGrid RadGrid1 = new RadGrid();

    protected void Page_Init(object sender, System.EventArgs e)
    {
        XmlDataSource source = new XmlDataSource();
        source.ID = "xmldata";
        source.EnableCaching = false;
        source.DataFile = "~/XMLFile.xml";
        source.XPath = "/Lines/Item";
        form1.Controls.Add(source);

        RadGrid1.ID = "RadGrid1";
        RadGrid1.DataSourceID = source.ID;
        RadGrid1.Width = Unit.Percentage(98);
        RadGrid1.PageSize = 5;
        RadGrid1.AllowPaging = true;
        RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
        RadGrid1.AutoGenerateColumns = false;
        GridBoundColumn boundColumn = new GridBoundColumn();
        boundColumn.DataField = "ID";
        boundColumn.HeaderText = "ID";
        RadGrid1.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "UserCode";
        boundColumn.HeaderText = "UserCode";
        RadGrid1.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Description";
        boundColumn.HeaderText = "Description";
        RadGrid1.MasterTableView.Columns.Add(boundColumn);
        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "ParentID";
        boundColumn.HeaderText = "ParentID";
        RadGrid1.MasterTableView.Columns.Add(boundColumn);
        RadGrid1.Skin = "Web20";
        RadGrid1.ClientSettings.AllowExpandCollapse = true;
        RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerOnDemand;// Client;
        RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
        RadGrid1.MasterTableView.DataKeyNames = new string[] { "ID", "ParentID" };

        RadGrid1.MasterTableView.SelfHierarchySettings.ParentKeyName = "ParentID";
        RadGrid1.MasterTableView.SelfHierarchySettings.KeyName = "ID";

        form1.Controls.Add(RadGrid1);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("3.5") != -1)
        {
            RadGrid1.MasterTableView.FilterExpression = "it[\"\"ParentID\"\"] = ''";
        }
        else
        {
            RadGrid1.MasterTableView.FilterExpression = "ParentID = ''";
        }

    }



}