0

I'd like to iterate over the value of each entry in a c# dictionary within my asp.net repeater.
My IDictionary is nothing special - Just key-value pairs of data, and the values are arrays of strings. I'm trying to create a form select element with materializecss (Docs, see "Optgroups"). Currently, what I have is this:

...
<div class="input-field">
    <asp:Repeater runat="server" ID="optgroupSelect">
        <HeaderTemplate>
            <select>
        </HeaderTemplate>
        <ItemTemplate>
            <optgroup label="<%# Eval("Key") %>">
                <%-- Here comes the problem --%>
                <%# foreach (string s in Eval("Value")) { %>
                    <option value="<%=s.toLower()%>"><%=s%></option>
                <%# } %>
            </optgroup>
        </ItemTemplate>
        <FooterTemplate>
            </select>
            <label>Please select something</label>
        </FooterTemplate>
    </asp:Repeater>
</div>
...

I've worked with PHP for the last couple years and feel that I'm missing the mindset of an asp.net dev - Still, I have to do this for work. Obviously, the above code does not work, but it highlights what I'd like to achieve. I've gone through the whole System.Web.UI.WebControls list to maybe find a component which could iterate over the databound value array, but most of them have their own style which I don't want (since everything should match with materializecss).
I appreciate any help towards solving this, thanks for taking your time!

Note: My pages are .aspx Web Forms in the Asp.net Framework 4.8

3x071c
  • 955
  • 10
  • 40
  • Any ideas in [here](https://stackoverflow.com/questions/130020/dropdownlist-control-with-optgroups-for-asp-net-webforms/27784921#27784921)? – wazz Oct 19 '19 at 17:47
  • @wazz Thanks a lot, that was what I was looking for ^^ What a bummer I wasn't able to find that answer during my search :( – 3x071c Oct 25 '19 at 15:33
  • Possible duplicate of [Dropdownlist control with s for asp.net (webforms)?](https://stackoverflow.com/questions/130020/dropdownlist-control-with-optgroups-for-asp-net-webforms/27784921#27784921) – wazz Oct 25 '19 at 22:31

0 Answers0