473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 1363

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Duncan Welch | last post by:
I have a strongly typed dataset that returns two tables - "items" and "itemdetails". In the strongly-typed dataset designer, I've created a link (relationship) between the two tables based on a...
1
by: Moojjoo | last post by:
Good Monday Morning: I am at a dead stop and I am hoping some other developers out there can help me out. I have built a dataset that first contains a table populated from SQL Server then I am...
2
by: James Zhuo | last post by:
Accessing Items in a Collection works with the as suggested by Kevin and Chris (thx) But when i tried to use the same technic with databinding within the aspx file, it doesn't seem to work. This...
2
by: Shafia | last post by:
Hi, My GridView has templated controls in it and I'm binding to an ObjectDataSource. The problem is it refused to bind to my grid column "ColumnName" which is also an UpdateCommand Parameter for...
20
by: Dennis | last post by:
I use the following code for a strongly typed arraylist and it works great. However, I was wondering if this is the proper way to do it. I realize that if I want to implement sorting of the...
3
by: keithb | last post by:
My code dynamically adds template fields to a GridView control. Everything seems to work OK, except when updating, because I haven't found a way to reference the dynamically added textboxes....
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
0
by: John Davis | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.