Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
Hashtable binding error
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngfreeforall' list.


Faisal Gazi
I've created a hashtable and bound a control to it:

protected void Page_Load(object sender, System.EventArgs e)
{
if (! Page.IsPostBack)
{
Hashtable hashPeople = new
Hashtable();
hashPeople.Add ("John", 1);
hashPeople.Add ("Paul", 3);
hashPeople.Add ("George", 5);
hashPeople.Add ("Ringo", 7);
hashPeople.Add ("Fred", 11);
hPeople.DataSource = hashPeople;
dList.DataBind();
}
}

When I attempt to bind to a DataList control with the following code:
<asp:DataList ID="dList" Runat="server"
OnItemCommand="ExecuteService" AlternatingItemStyle-BackColor="#cccc99">
<HeaderTemplate>
<b>Some Horoscopes</b>
</HeaderTemplate>
<ItemTemplate>
'<%# Container.DataItem.Key %>'
</ItemTemplate>
</asp:DataList>

I get the error:
Compiler Error Message: CS0117: 'object' does not contain a definition
for 'Key'

What am I missing?
cheers
Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
GfWeis
shouldn't this...

hPeople.DataSource = hashPeople;

dList.DataBind();

be more like this...

dList.DataSource = hashPeople;

dList.DataBind();

Gfw

-----Original Message-----
From: Faisal Gazi [mailto:Click here to reveal e-mail address]
Sent: Sunday, November 11, 2001 4:22 PM
To: aspngfreeforall
Subject: [aspngfreeforall] Hashtable binding error

I've created a hashtable and bound a control to it:

protected void Page_Load(object sender, System.EventArgs e)

{

if (! Page.IsPostBack)

{

Hashtable hashPeople = new
Hashtable();

hashPeople.Add ("John", 1);

hashPeople.Add ("Paul", 3);

hashPeople.Add ("George", 5);

hashPeople.Add ("Ringo", 7);

hashPeople.Add ("Fred", 11);

hPeople.DataSource = hashPeople;

dList.DataBind();

}

}

When I attempt to bind to a DataList control with the following code:

<asp:DataList ID="dList" Runat="server"
OnItemCommand="ExecuteService" AlternatingItemStyle-BackColor="#cccc99">

<HeaderTemplate>

<b>Some Horoscopes</b>

</HeaderTemplate>

<ItemTemplate>

'<%# Container.DataItem.Key %>'

</ItemTemplate>

</asp:DataList>

I get the error:

Compiler Error Message: CS0117: 'object' does not contain a definition for
'Key'

What am I missing?

cheers

| ASP.net DOCS = http://www.aspng.com/docs | [aspngfreeforall] member
Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP
Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
Faisal Gazi
In fact, it is. For some reason I amended the email code before I sent
it out.
So it is as you say it is (otherwise it wouldn't have compiled), but I
am still getting this error with the line at:
'<%# Container.DataItem.Key %>'

-----Original Message-----
From: GfWeis [mailto:Click here to reveal e-mail address]
Sent: 11 November 2001 22:33
To: aspngfreeforall
Subject: [aspngfreeforall] RE: Hashtable binding error

shouldn't this...
hPeople.DataSource = hashPeople;
dList.DataBind();

be more like this...
dList.DataSource = hashPeople;
dList.DataBind();

Gfw

-----Original Message-----
From: Faisal Gazi [mailto:Click here to reveal e-mail address]
Sent: Sunday, November 11, 2001 4:22 PM
To: aspngfreeforall
Subject: [aspngfreeforall] Hashtable binding error
I've created a hashtable and bound a control to it:

protected void Page_Load(object sender, System.EventArgs e)
{
if (! Page.IsPostBack)
{
Hashtable hashPeople = new
Hashtable();
hashPeople.Add ("John", 1);
hashPeople.Add ("Paul", 3);
hashPeople.Add ("George", 5);
hashPeople.Add ("Ringo", 7);
hashPeople.Add ("Fred", 11);
hPeople.DataSource = hashPeople;
dList.DataBind();
}
}

When I attempt to bind to a DataList control with the following code:
<asp:DataList ID="dList" Runat="server"
OnItemCommand="ExecuteService" AlternatingItemStyle-BackColor="#cccc99">
<HeaderTemplate>
<b>Some Horoscopes</b>
</HeaderTemplate>
<ItemTemplate>
'<%# Container.DataItem.Key %>'
</ItemTemplate>
</asp:DataList>

I get the error:
Compiler Error Message: CS0117: 'object' does not contain a definition
for 'Key'

What am I missing?
cheers

| ASP.net DOCS = http://www.aspng.com/docs | [aspngfreeforall] member
Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/aspngfreeforall JOIN/QUIT | news://ls.asplists.com = NEWSGROUP
| ASP.net DOCS = http://www.aspng.com/docs | [aspngfreeforall] member
Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/aspngfreeforall = JOIN/QUIT |
news://ls.asplists.com = NEWSGROUP
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Alex Lowe
Faisal,

In C# (not in VB.NET), you need to do a bit of casting because ASP.NET
does not know the data type of Container.DataItem. For example:

[VB]
<%# Container.DataItem.Key %>

[C#]
<%# ((DictionaryEntry)Container.DataItem).Key %>

Hth,
Alex - AspFriends.com Moderation Team

ASP.NET Examples/Tips: http://aspalliance.com/aldotnet

-----Original Message-----
From: Faisal Gazi [mailto:Click here to reveal e-mail address]
Sent: Sunday, November 11, 2001 6:47 PM
To: aspngfreeforall
Subject: [aspngfreeforall] RE: Hashtable binding error

In fact, it is. For some reason I amended the email code before I sent
it out.
So it is as you say it is (otherwise it wouldn't have compiled), but I
am still getting this error with the line at:
'<%# Container.DataItem.Key %>'

-----Original Message-----
From: GfWeis [mailto:Click here to reveal e-mail address]
Sent: 11 November 2001 22:33
To: aspngfreeforall
Subject: [aspngfreeforall] RE: Hashtable binding error

shouldn't this...
hPeople.DataSource = hashPeople;
dList.DataBind();

be more like this...
dList.DataSource = hashPeople;
dList.DataBind();

Gfw

-----Original Message-----
From: Faisal Gazi [mailto:Click here to reveal e-mail address]
Sent: Sunday, November 11, 2001 4:22 PM
To: aspngfreeforall
Subject: [aspngfreeforall] Hashtable binding error
I've created a hashtable and bound a control to it:

protected void Page_Load(object sender, System.EventArgs e)
{
if (! Page.IsPostBack)
{
Hashtable hashPeople = new
Hashtable();
hashPeople.Add ("John", 1);
hashPeople.Add ("Paul", 3);
hashPeople.Add ("George", 5);
hashPeople.Add ("Ringo", 7);
hashPeople.Add ("Fred", 11);
hPeople.DataSource = hashPeople;
dList.DataBind();
}
}

When I attempt to bind to a DataList control with the following code:
<asp:DataList ID="dList" Runat="server"
OnItemCommand="ExecuteService" AlternatingItemStyle-BackColor="#cccc99">
<HeaderTemplate>
<b>Some Horoscopes</b>
</HeaderTemplate>
<ItemTemplate>
'<%# Container.DataItem.Key %>'
</ItemTemplate>
</asp:DataList>

I get the error:
Compiler Error Message: CS0117: 'object' does not contain a definition
for 'Key'

What am I missing?
cheers

| ASP.net DOCS = http://www.aspng.com/docs | [aspngfreeforall] member
Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/aspngfreeforall =
JOIN/QUIT | news://ls.asplists.com = NEWSGROUP
| ASP.net DOCS = http://www.aspng.com/docs | [aspngfreeforall] member
Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/aspngfreeforall = JOIN/QUIT |
news://ls.asplists.com = NEWSGROUP
| ASP.net DOCS = http://www.aspng.com/docs | [aspngfreeforall] member
Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/aspngfreeforall = JOIN/QUIT |
news://ls.asplists.com = NEWSGROUP

Reply to this message...
Vote that this is a GOOD answer...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
 
System.Collections.DictionaryEntry
System.Collections.Hashtable
System.ComponentModel.Container
System.EventArgs
System.Web.UI.Page
System.Web.UI.WebControls.DataList




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734