471,089 Members | 1,276 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 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.(not sure if this posted the first time)

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)).Catego ryId

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

and

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

Cheers

John

Aug 31 '06 #1
0 1290

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.