PC Review


Reply
Thread Tools Rate Thread

accessing strongly typed properties of a datatable when binding through the objectdatasource and Container.DataItem

 
 
John Davis
Guest
Posts: n/a
 
      30th Aug 2006
Hi all, hope you are well.

I would like to know if I can access the strongly typed properties of my
datatable when binding through the ObjectDataSource object.

I am currently creating some hyperlinks in a repeater bound to an
objectdatasource with the following code:

<asp:HyperLink runat="server" ID="HyperLink1" NavigateUrl='<%#
string.Format("~/Products.aspx?page=0&categoryId={0}",
((System.Data.DataRowView)(Container.DataItem))["CategoryId"] ) %>'
Text='<%#
((System.Data.DataRowView)(Container.DataItem))["Name"] %>' />

or in particular:

((System.Data.DataRowView)(Container.DataItem))["CategoryId"]

This is as my ObjectDataSource is bound to a CategoriesBLL object that
returns a TypedDS.CategoriesDataTable and as far as I know the
ObjectDateSource does an implicit cast to a DataView making every
Container.DataItem a DataRowView.

But although the above code works I though that one of the points of
strongly typed objects was to do compile time checking on column/property
access and therefore thought that I thought I should be able to do something
like:

((TypedDS.CategoryRow)(Container.DataItem)).CategoryId

But this complains at runtime with: "Unable to cast object of type
'System.Data.DataRowView' to type 'CategoryRow'"

and

((TypedDS.CategoryRow)((System.Data.DataRowView)Container.DataItem)).CatgeoryId

complains at compile time with: "Cannot convert type
'System.Data.DataRowView' to 'TypedDS.CategoryRow'"

am I missing something or is this not possible?

Cheers

John


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
accessing strongly typed properties of a Datatable when binding through the ObjectDataSource and Container.DataItem John Davis Microsoft ASP .NET 0 31st Aug 2006 12:56 PM
sql datetime format not right when using objectdatasource with strongly typed tableadapter AlanJSmith Microsoft Dot NET 0 21st Jun 2006 02:58 PM
DetailsView ObjectDataSource and strongly typed dataset Spotnick Microsoft ADO .NET 0 21st Jan 2006 07:56 PM
DetailsView ObjectDataSource and strongly typed dataset Spotnick Microsoft ASP .NET 0 21st Jan 2006 07:56 PM
DetailsView ObjectDataSource and strongly typed dataset Spotnick Microsoft Dot NET 0 21st Jan 2006 07:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:46 PM.