This is a migrated thread and some comments may be shown as answers.

Grid : Populate the textbox

1 Answer 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 01 Nov 2012, 03:44 AM
Hi all,

I have a radgrid in which I need to populate a textbox(boundcolumn) when clicking on the insert button. The first textbox should populate value of 
boundcolumn(name) in the first row.

Thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 01 Nov 2012, 04:46 AM
Hi,

Please try the following code snippet to populate the TextBox in insert form with the value of the GridBoundColumn in first row.

C#:
static string value = string.Empty;
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.InitInsertCommandName)
    {
        e.Canceled = true;
        e.Item.OwnerTableView.InsertItem();
        GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
        GridEditFormItem editFormItem = insertedItem as GridEditFormItem;
             
        TextBox txt = (TextBox)insertedItem["UniqueName"].Controls[0];
        txt.Text = value;
    }
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem ditem = (GridDataItem)e.Item;
        if (ditem.ItemIndex == 0)
        {
            value = ditem["UniqueName"].Text;
        }
    }
}

Thanks,
Shinu.
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or