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

a Grid.DataItem should be a DataBinded Object type, right?

1 Answer 364 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Søren Hartig
Top achievements
Rank 2
Søren Hartig asked on 28 May 2009, 01:11 PM
Hi all,

when we're binding a Collection of a Business Object into the Grid, the grid.DataItem should be that type, right?

I'm getting null :(

Code:

List<DocumentRow> rows = new List<DocumentRow>(); 
...  
while (reader.Read()) 
   DocumentRow row = DocumentRow.GetFromIdxDocumentId(int.Parse(reader[0].ToString())); 
   rows.Add(row);    
... 
gvDocs.DataSource = rows; 
gvDocs.DataBind(); 

when trying to get the selected items...

foreach (GridItem gvr in gvDocs.SelectedItems) 
   DocumentRow row = (DocumentRow)gvr.DataItem; 
   list.Add(row.DocumentId); 

gvr.DataItem is always null! :-(

how do I get the data back?






1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 29 May 2009, 03:07 PM
Hello Søren,

I have answered to the support ticket opened the same matter. Here is a quote of the answer:

Thank you for contacting us.

This is an expected behavior. You can reach the DataItem only in the ItemDataBound event handler. In any other later stage the grid is already bound and the DataItem will be null. In other words when the grid is bound the data source is not required anymore and it is null.

To retrieve the required data, you can make a call to the server to get the data or use the grid functionality to extract the data from the rows.

Let me know if I can assist you further.


May I ask you to continue our discussion in the opened support thread? Thus we will avoid any duplication and misunderstanding.

All the best,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Søren Hartig
Top achievements
Rank 2
Answers by
Georgi Krustev
Telerik team
Share this question
or