| | |
Repeater with Object as Value
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
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: -
In the webform codebehind: -
ASP html
~ Lacuna
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)
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: -
C# Syntax (Toggle Plain Text)
TestSome myTest = new TestSome(); this.myRepeater.DataSource = myTest.myHash; this.myRepeater.DataBind();
ASP html
C# Syntax (Toggle Plain Text)
<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:
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
I should be using:
C# Syntax (Toggle Plain Text)
<%# ((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
![]() |
Similar Threads
- 'Object variable or With block variable not set' Error (ASP.NET)
- asp:repeater in a form? (ASP.NET)
- Datagrid inside repeater-simple reference problem (ASP.NET)
- Object-Oriented Programming (C++)
- infected, embedded object. (Viruses, Spyware and other Nasties)
- Print Object hierarchy (C)
Other Threads in the C# Forum
- Previous Thread: Im Stumped Once More!!
- Next Thread: database question
| Thread Tools | Search this Thread |
.net access algorithm array backup barchart bitmap box broadcast buttons c# check checkbox client clock combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees developer development draganddrop drawing dynamiccreation encryption enum excel file form format forms function gdi+ hospitalmanagementsystems httpwebrequest image index input install interface java label list listbox mandelbrot math microsystems mouseclick mysql operator password path photoshop picturebox pixelinversion post priviallages. programming property radians regex remoting richtextbox running... serialization server sleep soap socket sql sqlserver stack statistics stream string table temperature text textbox thread time timer update usercontrol validation visualstudio webbrowser windows windowsformsapplication winforms wpf write xml





