473,698 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

container.datai tem cast throws exception

I have a class, lets call it Schmuck. It has 2 public properties Name
(string) and active (boolean). When I bind to a Repeater, like so:
<%#container.da taitem("Name")% > i get the following error: No default
datamember found for type Schmuck. The Schmucks are in a ArrayList.
When I use DataBinder.Eval , i have no prob. But for say the boolean
Active property, I want to pass to a function like so:
<%#fx(CBool(con tainer.dataitem ("Active"))) %> so i want to get away from
the Eval syntax ( for overhead reasons as well ). But why am i gettin
this error. Thanks for any advice......

Nov 19 '05 #1
4 1810
What about using :container.data item.Name.

I think DataItem returns whatever object is being bound to. If you are
binding to a datatable, each dataitem is a DataRow, which happens to have an
indexer where you can index by column name.

Since you are binding to a collection of Schmucks, the DataItem should be a
Schmuck object, so you should be able to call .Name on it. You might have
to cast it to a Schmuck first.

<hs********@yah oo.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
I have a class, lets call it Schmuck. It has 2 public properties Name
(string) and active (boolean). When I bind to a Repeater, like so:
<%#container.da taitem("Name")% > i get the following error: No default
datamember found for type Schmuck. The Schmucks are in a ArrayList.
When I use DataBinder.Eval , i have no prob. But for say the boolean
Active property, I want to pass to a function like so:
<%#fx(CBool(con tainer.dataitem ("Active"))) %> so i want to get away from
the Eval syntax ( for overhead reasons as well ). But why am i gettin
this error. Thanks for any advice......

Nov 19 '05 #2
Correct,

just to add that when you bind to a DataTable, DataView etc the type of item
is always DataRowView (type of item in DataView). With dataReader it is
System.Data.Com mon.DBDataRecor d. Of course with custom collection, it is the
type of the collection item. :-)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
Nov 19 '05 #3
ok, thats sounds good. I dont have .NoT with me now bit will try when I
get home and let ya know hot it worked. It makes sense though because
the error says ".... no default property ..." that should have told me
it was trying to do a Object("index") type lookup.
Also, Marina that last paragraph sounds funny, with the Schmuck this
and Schmuck that. HA!

Nov 19 '05 #4
yup that works. Thanks again!

Nov 19 '05 #5

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

Similar topics

0
1897
by: Brent | last post by:
I maintain a Sql Server database application whose forms are compiled in a .dll and kept in a remote web folder. The main .exe looks to the web folder to see if this .dll exists. If so, then it compares the ..dll with the cache copy. If the cache copy is older then it downloads a new copy. If the .dll is not present, it throws an error. In my main .exe, I need to early bind my "Main" form from my FormsLibrary.dll to get data into it. If...
5
3424
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
2
8984
by: JohnZing | last post by:
Hi, Should I use <%# Container.DataItem("Author")%> or <%# DataBinder.Eval(Container.DataItem,"Author") %> What's the difference between both? Thank You
0
1763
by: Aaron Prohaska | last post by:
Is it possible to cast the DataItem of the repeater control to a typed datatable? I'm trying to use the following code to do this and it doesn't work. This code always throws an invalid cast exception. private void frameRepeater_ItemCreated(object sender, RepeaterItemEventArgs e) { FramesRow frame = e.Item.DataItem as FramesRow;
2
6083
by: wubin_98 | last post by:
Hi All, Could any expert point out what is wrong in my code? I search around but couldn't found answer. It seems that I am the first person have this problem. Thanks in advanced I have a gridview that one column contains a dropDownList and a SqlDataSource control. I try to set up dropDownList selection by following code.
0
1315
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 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}",
0
1383
by: John Davis | last post by:
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}",
3
3454
by: alberthung01 | last post by:
Hi all, I try to use Container.DataItem() in my DataGrid's ItemTemplate. Somewhere it works fine. eg.<input type=checkbox id='cb_select_<%# Container.DataItem("TAG_ID") %>' value='<%# Container.DataItem("TAG_NAME") %>'> but somewhere the server returns the expression was wrong. <asp:ImageButton id="IB_Edit<%# Container.DataItem("TAG_ID") %>" runat="server" ImageUrl="../Image/edit_image.gif" CommandName="TO_EDIT"></asp:ImageButton>
6
15844
by: rn5a | last post by:
What's the difference between <%# DataBinder.Eval(Container.DataItem,"LastName") %> & <%# Container.DataItem("LastName") %> Thanks
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9026
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.