|
| 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
|
|
|
| |
|
| |
| |
| 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
|
|
|
| |
|
| |
|
| |
| 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
|
|
|
| |
|
|
| |
|
| |
| 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
|
|
|
| |
|
| |
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|