471,122 Members | 1,128 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,122 software developers and data experts.

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

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='<%#
((System.Data.DataRowView)(Container.DataItem))["CategoryId"] ) %>'
((System.Data.DataRowView)(Container.DataItem))["Name"] %>' />

or in particular:


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

((TypedDS.CategoryRow)(Container.DataItem)).Catego ryId

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


((TypedDS.CategoryRow)((System.Data.DataRowView)Co ntainer.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?


Aug 30 '06 #1
0 1191

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Duncan Welch | last post: by
2 posts views Thread by James Zhuo | last post: by
20 posts views Thread by Dennis | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.