Set Control Value OnCommand (Add New Item)

4 posts, 0 answers
  1. Omer B
    Omer B avatar
    7 posts
    Member since:
    Feb 2014

    Posted 25 Aug 2014 Link to this post

    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.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Aug 2014 in reply to Omer B Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Omer B
    Omer B avatar
    7 posts
    Member since:
    Feb 2014

    Posted 25 Aug 2014 in reply to Princy Link to this post

    Sorry but i forgot to mention, i need to do that client side way.
  5. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 28 Aug 2014 Link to this post

    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.

     
Back to Top