accessing strongly typed properties of a Datatable when binding through the ObjectDataSource and Con

J

John Davis

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top