J
John Davis
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
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