+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Get currently added Row in RadGrid

Get currently added Row in RadGrid

4 posts, 0 answered
  1. Varinder Kumar
    Varinder Kumar avatar
    15 posts
    Registered:
    13 Apr 2010
    09 Aug 2010
    Link to this post
    Hello All, 

    I need to get the row which currently added in radgrid, so that I can show a message that <this row> is added successfully.

    Thanks.
    Varinder Kumar
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Aug 2010
    Link to this post

    Hi Varinder Kumar,

    You can access the last inseted row by getting the first item of the RadGrid  RadGrid1.Items[0]
    The GridTableView object has an Items property that contains all the data rows in the table view. Each row is represented by a GridDataItem or GridEditFormItem object, depending on whether the row is an edit form. The GridDataItem or GridEditFormItem has an ItemIndex property that is its index in the Items property collection.
    When implementing an event handler for an event such as ItemCreated, ItemDataBound, ItemCommand, UpdateCommand, InsertCommand, or DeleteCommand, you can obtain a GridDataItem or GridEditFormItem for the row from the event arguments (e.Item or, in a hierarchical grid, e.Item.OwnerTableView.ParentItem)

     

    If you are working on the client you can get the  first data item

    var itm= $find("<%=RadGrid1.ClientID %>").get_masterTableView().get_dataItems()[0];

     

    and later operate with it.


    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Mukesh
    Mukesh avatar
    1 posts
    Registered:
    03 Aug 2010
    18 Sep 2010
    Link to this post
    Hi Ivan,

    The above solution is working after New row is inserted.

    But I want to access the row's Item just after when user click on "Add Row" button.
    Please note, user has not updated the row.

    So, I am unable to get it in .get_dataItems().

    Please advise me some idea..


    Thanks
    Mukesh
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    20 Sep 2010
    Link to this post
    Hello Mukesh,

    When you click "Add Row" this does not commit anything to your data source and there is not such row- you cannot get the row before you add it to your data source. You can only get some data from the EditFormInserItem and make some validation or observe what is going to be inserted as a row.

    Inside ItemDataBound get the GridEditFormInsertItem. Find your TextBox or the control that you are using to insert some value. Then register StartupScript and send the id to the client. Inside gridCommand function get the value of the Textbox/other control by using

    if(args.get_commandName() == "PerformInsert")

    or you can access the control directly

    function gridCommand(sender, args) {
                  if (args.get_commandName() == "PerformInsert") {
                      var name = $("input[name*='Name']");
                     
                  }
              }

    This will give you information about the row that is going to be inserted. My previous reply gives you solution about the first inserted row that exists in your data source.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
4 posts, 0 answered