| | |
Repeater with Object as Value
Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
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 angle array asp.net bitmap box broadcast c# capturing check checkbox client combobox control conversion csharp database databasesearch datagrid datagridview dataset datetime dbconnection degrees delegate design development disappear draganddrop drawing encryption enum eventhandlers excel file firefox form format forms function gdi+ grantorrevokepermissionthroughc#.net image input install interface java libraries list loop marshalbyrefobject math monodevelop mouseclick movingimage msword mysql operator path pause photoshop php picturebox pixelinversion platform post programming radians regex remoting richtextbox server sleep socket sql statistics string study system.servicemodel table tcpclientchannel text textbox thread time timer update usb usercontrol validation virtualization visualbasic visualstudio webbrowser winforms wpf wpfc# xml





