Multimobile Development: Building Applications for any Smartphone
Hashtable binding error
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngfreeforall' list.


Faisal Gazi
GOOD ANSWER
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... (9 votes from other users already)
 
 
    
GfWeis
GOOD ANSWER
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... (9 votes from other users already)
 
 
    
Faisal Gazi
GOOD ANSWER
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... (5 votes from other users already)
 
 
    
Alex Lowe
GOOD ANSWER
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... (5 votes from other users already)
 
 
 
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.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734