Background
In our last adventure, I was attempting to properly show a Dictionary<Foo, Bar<T>>
. Thanks to the helpful answers in that post, I realize I had been going about it in the wrong way.
Problem
In today's adventure, I've been trying to get two specific properties from the List<T>
in the last question to display. Each List has specific properties, shown below:
--------------------- | Bar Class | --------------------- | Id int | | Foo.Id int | | Name string | | Type string | ---------------------
For display, I'd like to display the Bar.Name + Bar.Type
, concatenated together. Obviously I have to retain the complete object, since the Id will be passed back to be sent to the database.
At first, I tried <%#Eval("Value.Type" + "Value.Name")%>
, clearly that did not work. My guess now is that I need to write a foreach loop to iterate through the Dictionary Object, and retrieve the Dictionary.Value
Objects intact, and build a dropdown list out of that. But then, the problem becomes tying that back to the associated profile, and sending it back to the database wholesale.
Here currently is how the page looks:
<tr><td align="center"> <%#Eval("Key.Name") %></td>
<td align="center"><asp:DropDownList ID="ddlListOfBars" runat="server"
DataSource='<%#Eval("Value")%>' DataValueField="Id" DataTextField="Type" />
</td>
I've been monkeying around with different ways of changing the DataTextField
but haven't yet figured out a combination that works.
Questions
- Am I overthinking this?
- What am I missing?
- Is there a resource for how you would pull specific properties out of the
List<T>
to use those values as the display Values for theDropDownList
, and if so, is there a good resource on that topic? - Is this post as clear as mud?