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

Set Control Value OnCommand (Add New Item)

3 Answers 18 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Omer B
Top achievements
Rank 1
Omer B asked on 25 Aug 2014, 08:30 AM
Dear All,
I want to set the value of a text box when the user click "Add New Item".
I want to set the value in the new crated row.
Please advise how do i get a reference to the column/field that i need.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 25 Aug 2014, 08:39 AM
Hi Omer B,

I guess you want a TextBox in Insert form to be filled with a default value. Please try the following code snippet:

C#:
//ItemCommand event of Rdagrid
protected void rgrdSample_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.InitInsertCommandName)
    {
        e.Canceled = true;
        e.Item.OwnerTableView.InsertItem();
        GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
        //Bound Column textbox access using UniqueName
        TextBox txtID = (TextBox)insertedItem["ID"].Controls[0];
        txtID.Text = "12";
        //Template column TextBox access using ID
        TextBox txt = (TextBox)insertedItem.FindControl("txtID");
        txt.Text = "123";
    }
}

Thanks,
Princy
0
Omer B
Top achievements
Rank 1
answered on 25 Aug 2014, 08:41 AM
Sorry but i forgot to mention, i need to do that client side way.
0
Eyup
Telerik team
answered on 28 Aug 2014, 08:33 AM
Hi Omer,

You can use the following event handler to achieve this requirement:
http://www.telerik.com/help/aspnet-ajax/grid-onrowcreated.html

Once you have the container element, you can use the $telerik.findElement or $telerik.findControl methods to access the textbox in question as demonstrated in the last part of the following post:
http://www.telerik.com/forums/javascript-on-each-item#FpwQalBeNkGNGYJoZBJYhg


Hope this helps.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Omer B
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Omer B
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or