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;
using Telerik.Web.UI;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    public DataTable Data
    {
        get
        {
            if (Session["Data"] == null)
            {
                DataTable table = new DataTable();
                table.Columns.Add("ID", typeof(Int32));
                table.Columns.Add("Items");
                for (int i = 1; i <= 10; i++)
                {
                    table.Rows.Add(i, "Item" + i.ToString());
                }
                Session["Data"] = table;
            }
            return (DataTable)Session["Data"];
        }
    }
    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        RadGrid1.DataSource = Data;
    }
    protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        DataTable table = Data;
        DataRow[] changedRows = table.Select("ID = " +
             editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["ID"].ToString());
        if (changedRows.Length != 1)
        {
            this.Label1.Text += "Unable to locate the Order for updating.";
            e.Canceled = true;
            return;
        }
        //Update new values
        Hashtable newValues = new Hashtable();
        e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
        changedRows[0].BeginEdit();
        try
        {
            foreach (DictionaryEntry entry in newValues)
            {
                changedRows[0][(string)entry.Key] = entry.Value;
            }
            changedRows[0].EndEdit();
        }
        catch (Exception ex)
        {
            changedRows[0].CancelEdit();
            Label1.Text += "Unable to update Orders. Reason: " + ex.Message;
            e.Canceled = true;
        }
        TextBox txt = editedItem["Template_Column"].FindControl("TextBox1") as TextBox;
        Label1.Text = "TemplateColumn TextBox.Text: <b>" + txt.Text + "</b>";
    }
}
