473,399 Members | 3,038 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,399 software developers and data experts.

asp:repeater and hashtable - also in languages.csharp

Sorry about the multi post, I thought I'd sent to both groups simultaneously but
somehow it failed to find this one the first time.

I'm having a problem binding an asp:repeater control to a Hashtable. Originally
my code was:

<asp:Repeater id="rptFamily" runat="server" DataSource="<%# family %>">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Key") %> =
<%# DataBinder.Eval(Container.DataItem, "Value") %>
</ItemTemplate>
</asp:Repeater>

which was bound to a Hashtable and all works fine. I then started reading that
Databind.Eval was an overkill, I could just use:

<asp:Repeater id="rptFamily" runat="server" DataSource="<%# family %>">
<ItemTemplate>
<%# Container.DataItem.Key %> =
<%# Container.DataItem.Value %>
</ItemTemplate>
</asp:Repeater>

but although I can build the site when accessing the page I get an error that :

'object' does not contain a definition for 'Key'

pointing to the first changed line. I've found lots of examples on the Web
showing this second version, are they all perhaps from a beta version or is it
something else?

Thanks

--

Joe

Nov 19 '05 #1
3 2512
Joe:

Try:

<%# ((DictionaryEntry)Container.DataItem).Key %>
<%# ((DictionaryEntry)Container.DataItem).Value%>

Container.DataItem is of type object
object doesn't container a "key" or "value" property

You need to explicitely cast it to the underlying type that is being bound.
When you are binding to a DataSet/DataTable/DataView, Container.DataItem is
always a "DataRowView"...

DataBinder.Eval does have performance implications, but on the flip side it
lets you change the underlying datasource implementation without breaking
your code...ie, using DataBinder.Eval you could switch to a dataset, and as
long as it had a property named "key" and "value" everything would continue
to work...

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Joe Fawcett" <jo********@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Sorry about the multi post, I thought I'd sent to both groups simultaneously but somehow it failed to find this one the first time.

I'm having a problem binding an asp:repeater control to a Hashtable. Originally my code was:

<asp:Repeater id="rptFamily" runat="server" DataSource="<%# family %>">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Key") %> =
<%# DataBinder.Eval(Container.DataItem, "Value") %>
</ItemTemplate>
</asp:Repeater>

which was bound to a Hashtable and all works fine. I then started reading that Databind.Eval was an overkill, I could just use:

<asp:Repeater id="rptFamily" runat="server" DataSource="<%# family %>">
<ItemTemplate>
<%# Container.DataItem.Key %> =
<%# Container.DataItem.Value %>
</ItemTemplate>
</asp:Repeater>

but although I can build the site when accessing the page I get an error that :
'object' does not contain a definition for 'Key'

pointing to the first changed line. I've found lots of examples on the Web
showing this second version, are they all perhaps from a beta version or is it something else?

Thanks

--

Joe

Nov 19 '05 #2
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:uu**************@tk2msftngp13.phx.gbl...
Joe:

Try:

<%# ((DictionaryEntry)Container.DataItem).Key %>
<%# ((DictionaryEntry)Container.DataItem).Value%>

Container.DataItem is of type object
object doesn't container a "key" or "value" property

You need to explicitely cast it to the underlying type that is being bound.
When you are binding to a DataSet/DataTable/DataView, Container.DataItem is
always a "DataRowView"...

DataBinder.Eval does have performance implications, but on the flip side it
lets you change the underlying datasource implementation without breaking
your code...ie, using DataBinder.Eval you could switch to a dataset, and as
long as it had a property named "key" and "value" everything would continue
to work...

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)

Thanks, it works. So does that mean that the example code I've seen, using a
HashTable, was wrong?

--

Joe
Nov 19 '05 #3
Since I haven't seen the example code, I can't really say...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Joe Fawcett" <jo********@newsgroups.nospam> wrote in message
news:u8**************@TK2MSFTNGP10.phx.gbl...
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:uu**************@tk2msftngp13.phx.gbl...
Joe:

Try:

<%# ((DictionaryEntry)Container.DataItem).Key %>
<%# ((DictionaryEntry)Container.DataItem).Value%>

Container.DataItem is of type object
object doesn't container a "key" or "value" property

You need to explicitely cast it to the underlying type that is being bound. When you are binding to a DataSet/DataTable/DataView, Container.DataItem is always a "DataRowView"...

DataBinder.Eval does have performance implications, but on the flip side it lets you change the underlying datasource implementation without breaking your code...ie, using DataBinder.Eval you could switch to a dataset, and as long as it had a property named "key" and "value" everything would continue to work...

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)

Thanks, it works. So does that mean that the example code I've seen, using

a HashTable, was wrong?

--

Joe

Nov 19 '05 #4

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

Similar topics

0
by: Joe Fawcett | last post by:
I'm having a problem binding an asp:repeater control to a Hashtable. Originally my code was: <asp:Repeater id="rptFamily" runat="server" DataSource="<%# family %>"> <ItemTemplate> <%#...
2
by: Peter Kirk | last post by:
Hi are there any "gotchas" with using an asp:repeater that means that the "onclick" method of a LinkButton created in the repaeter does not fire? I at least cannot get it to work. I have a...
5
by: Scott Lyon | last post by:
I am having a strange problem. The program is a bit complex, but I'll try to simplify what I can. I apologize if this is complicated, but I think this would still be simpler than posting a bunch of...
4
by: Eric | last post by:
Hello, I have the following dataset that I want to bind to a repeater to be displayed as a table. Owner Animal Volume --------------------------- Eric Dog 6 Eric Cat ...
3
by: Kelly Leahy | last post by:
I'm using an Asp:Repeater control with a text box in the item templates. This is for a system that has a number of items that the user can edit and I'd like to generate them based on a list. ...
8
by: dhnriverside | last post by:
Hi I'm using an asp:repeater and its DataSource/DataBind system to show a number of records from the database. I want to highlight the latest record (which will be the highest ID). Any...
1
by: Fred Dag | last post by:
As far as I can work out when using the OnTextChanged event I cannot get the TextBox and Labels values when the event fires as they are populated by a <asp:repeater and so don't have values. If...
1
by: Timbo | last post by:
Hi all, This is my first message here so i'll try and include all the information that will help you help me out, if possible. Basically I am using C# in ASP.NET 2.0 and have a Repeater...
2
by: bissatch | last post by:
Hi, I am trying to output a list of checkboxes. Using ASP .NET controls, I was able to create the following: <label for="colour_red">Red: </label><asp:CheckBox ID="colour_red" runat="server"...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.