get grid row collection from GridDataItem

4 posts, 0 answers
  1. JJ
    JJ avatar
    147 posts
    Member since:
    May 2010

    Posted 31 Dec 2011 Link to this post

    I know on grid_ItemDataBound can use
    e.Item.DataItem to get the collection.



    can use  


    GridDataItem dataItem1 = e.Item as GridDataItem;  

    dataItem1["fieldname"] to get the field name.

    Is it a way to get the collection just based on dataItems1?

    I have a dropdown inside grid cell, on the dropdown click, I like to pass the row collection to the dropdown click. How can I do this?
    On mydropdown_SelectedIndexChanged I used below:    

    DropDownList ddl = (DropDownList)sender;
    GridDataItem item = (ddl.Parent as GridTableCell).Parent as GridDataItem;  


    string field=item["field1"];
    to pass grid field to mydropdown_SelectedIndexChanged 

    this way, I need to put all the field1. field 2 in the grid (maybe hidden column) in order to let mydropdown_SelectedIndexChanged  access the grid data, is there a way to send the whole grid row collection to mydropdown_SelectedIndexChanged ? something like (Myrowcollection)e.Item.DataItem that I did on ItemDataBound,but don't how to get the collection under mydropdown_SelectedIndexChanged?


  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 Jan 2012 Link to this post


    You can access the row using NamingContainer property.
    protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
         DropDownList ddl = (DropDownList)sender;
         GridDataItem item = (GridDataItem)ddl.NamingContainer;

  3. DevCraft R3 2016 release webinar banner
  4. JJ
    JJ avatar
    147 posts
    Member since:
    May 2010

    Posted 03 Jan 2012 Link to this post

    Thanks Shinu.
    But how I access convert the item to the Object, I like to get the whole row Object at one time, instead of using dataItem1["fieldname"] to get the field name.  What I mean is if I don't put all the collection field name in the grid, can I get them also fromGridDataItem item ?

    something like (Myrowcollection)e.Item.DataItem

    ps, I have 'Subscribe me for this thread " checked, but recently I didn't get email alert when someone replys my email
  5. Sebastian
    Sebastian avatar
    9934 posts

    Posted 04 Jan 2012 Link to this post

    Hi JJ,

    The DataItem object is not null only in data-bound context, i.e. inside the ItemDataBound event handler of the grid (the same holds true for the regular MS GridView control). Therefore, your option is to extract the data from the relevant items accessing the cells by using the columns' unique names (see this demo for reference).

    I will pass your comment on the subscription for forum threads to our site administrators to research the matter.

    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top