DataGrid binding and TypedLists question

Posts   
 
    
exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 19-Apr-2006 22:51:53   

I generated a typed list and I am binding it to asp.net datagrid. In Item_DataBound event I am trying to convert e.item.dataitem into typelists row like this but it does not work since the dataitem is of DataRowView type.

Dim alertRow As TypedListClasses.PublishedUserAlertsRow = DirectCast(e.Item.DataItem, TypedListClasses.PublishedUserAlertsRow)

I tought that the type of the item would be as above. What is then this generated row used for?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 20-Apr-2006 03:10:19   

I believe that's an artifact of Databinding. Cast the data item to a DataRowView. The DataRowView object's Row property will contain the TypedListClasses.PublishedUserAlertsRow instance.


Dim alertRow As TypedListClasses.PublishedUserAlertsRow = DirectCast(DirectCast(e.Item.DataItem, DataRowView).Row, TypedListClasses.PublishedUserAlertsRow)
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 21-Apr-2006 18:11:05   

This is caused by the fact that a datatable doesn't bind directly to a control, it binds via a DataView. So the current object in the control isn't a datarow, but a dataview. Brian's example shows you how to work around that simple_smile

Frans Bouma | Lead developer LLBLGen Pro