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;
using System.Drawing;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        var grid = new RadGrid();
        grid.ID = "Grid";
        grid.AutoGenerateColumns = false;
        grid.AutoGenerateEditColumn = true;
        grid.MasterTableView.EditMode = GridEditMode.InPlace;

        GridBoundColumn boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Field";
        grid.MasterTableView.Columns.Add(boundColumn);

        boundColumn = new GridBoundColumn();
        boundColumn.DataField = "Field1";
        boundColumn.ReadOnly = true;
        boundColumn.ForceExtractValue =  GridForceExtractValues.Always;
        grid.MasterTableView.Columns.Add(boundColumn);

        grid.CreateColumnEditor += (s, a) =>
        {
            if ((a.Column as GridBoundColumn).DataField == "Field")
            {
                a.ColumnEditor = new MultiLineTextBoxColumnEditor();
            }
        };
        grid.NeedDataSource += (s, a) =>
        {
            ((RadGrid)s).DataSource = Enumerable.Range(0, 5).Select(i =>
                new { Field = i, Field1 = "Field1" + i }
                );
        };

        grid.UpdateCommand += (s, a) =>
        {
            Hashtable newValues = new Hashtable();
            (a.Item as GridDataItem).ExtractValues(newValues);

            var field1Value = newValues["Field1"];

            string text = ((a.Item as GridDataItem)["Field"].Controls[0] as TextBox).Text;

            RadAjaxManager1.Alert(string.Format("TextBox's Text: {0} , Field1: {1}", text, field1Value));

        };

        Panel1.Controls.Add(grid);
    }
}

public class MultiLineTextBoxColumnEditor : GridTextColumnEditor
{
    private TextBox textBox;
    protected override void LoadControlsFromContainer()
    {
        this.textBox = this.ContainerControl.Controls[0] as TextBox;
    }
    public override bool IsInitialized
    {
        get
        {
            return this.textBox != null;
        }
    }
    public override string Text
    {
        get
        {
            return this.textBox.Text;
        }
        set
        {
            this.textBox.Text = value;
        }
    }
    protected override void AddControlsToContainer()
    {
        this.textBox = new TextBox();
        this.textBox.TextMode = TextBoxMode.MultiLine;
        this.textBox.Rows = 4;
        this.textBox.Columns = 40;
        this.textBox.BackColor = Color.Crimson;
        this.textBox.ForeColor = Color.White;
        this.ContainerControl.Controls.Add(this.textBox);
    }
}




