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

get grid row collection from GridDataItem

3 Answers 580 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JJ
Top achievements
Rank 1
JJ asked on 31 Dec 2011, 04:18 PM
I know on grid_ItemDataBound can use
e.Item.DataItem to get the collection.

 

 also

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;  

 

use
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?

Thanks

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Jan 2012, 06:00 AM
Hello,

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

-Shinu.
0
JJ
Top achievements
Rank 1
answered on 03 Jan 2012, 08:38 PM
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
0
Sebastian
Telerik team
answered on 04 Jan 2012, 04:11 PM
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.

Regards,
Sebastian
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
Tags
Grid
Asked by
JJ
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
JJ
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or