Start New Discussion within our Software Development Community

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: -

Class SomeClass 
{ 
public String myProperty1 
public String myProperty2 

    public SomeClass() 
    { 
        this.myProperty1 = "hello"; 
        this.myProperty2 = "goodbye"; 
    } 
} 


Class TestSome 
{ 
    public Hashtable myHash    = new Hashtable(); 

    public TestSome() 
    { 
        myHash.Add("key1", new SomeClass()); 
    } 

}

In the webform codebehind: -

TestSome myTest = new TestSome(); 
this.myRepeater.DataSource = myTest.myHash; 
this.myRepeater.DataBind();

ASP html

<asp:repeater id=myRepeater runat="server"> 
<ItemTemplate> 
    <DIV style="FLOAT: left; MARGIN-LEFT: 10px"> 
    <asp:Label id="Label2" runat="server" Width="160px"> 


        <!-- how do i specify that i wish to use the class's properties here? --> 
        <%# DataBinder.Eval(Container.DataItem, "myProperty1") %> 
         

        <%# DataBinder.Eval(Container.DataItem, "myProperty2") %> 

    </asp:Label> 
    </DIV> 
    </ItemTemplate> 
</asp:repeater>

~ Lacuna

I found the problem :)

I should be using:

<%# ((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

This article has been dead for over six months. Start a new discussion instead.