944,131 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 10407
  • C# RSS
Aug 15th, 2005
0

Repeater with Object as Value

Expand Post »
I am trying to iterate through a hashtable that i have populated with objects using the repeater control.
For each iteration i wish to output the values of properties of the objects I am populating the hashtable with.


For example: -

C# Syntax (Toggle Plain Text)
  1.  
  2.  
  3. Class SomeClass
  4. {
  5. public String myProperty1
  6. public String myProperty2
  7.  
  8. public SomeClass()
  9. {
  10. this.myProperty1 = "hello";
  11. this.myProperty2 = "goodbye";
  12. }
  13. }
  14.  
  15.  
  16. Class TestSome
  17. {
  18. public Hashtable myHash = new Hashtable();
  19.  
  20. public TestSome()
  21. {
  22. myHash.Add("key1", new SomeClass());
  23. }
  24.  
  25. }

In the webform codebehind: -

C# Syntax (Toggle Plain Text)
  1.  
  2. TestSome myTest = new TestSome();
  3. this.myRepeater.DataSource = myTest.myHash;
  4. this.myRepeater.DataBind();

ASP html
C# Syntax (Toggle Plain Text)
  1.  
  2. <asp:repeater id=myRepeater runat="server">
  3. <ItemTemplate>
  4. <DIV style="FLOAT: left; MARGIN-LEFT: 10px">
  5. <asp:Label id="Label2" runat="server" Width="160px">
  6.  
  7.  
  8. <!-- how do i specify that i wish to use the class's properties here? -->
  9. <%# DataBinder.Eval(Container.DataItem, "myProperty1") %>
  10.  
  11.  
  12. <%# DataBinder.Eval(Container.DataItem, "myProperty2") %>
  13.  
  14. </asp:Label>
  15. </DIV>
  16. </ItemTemplate>
  17. </asp:repeater>
  18.  

~ Lacuna
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lacuna is offline Offline
19 posts
since May 2005
Aug 15th, 2005
0

Re: Repeater with Object as Value

I found the problem

I should be using:

C# Syntax (Toggle Plain Text)
  1.  
  2. <%# ((SomeClass)Container.DataItem).myProperty1 %>

instead of the 'Databinder.Eval' statement. I can then repeat this statement changing the propery value to show each of the properties I want to show.

It works great now.

~ Lacuna
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lacuna is offline Offline
19 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Im Stumped Once More!!
Next Thread in C# Forum Timeline: database question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC