0

I have a dropdown from boostrap such as this:

<div class="dropdown">
     <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
           <i class="fa fa-bell-o"></i>
    <span class="caret"></span>
     </button>
           <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
           </ul>
</div>

I'd like to add list items to this boostrap dropdown menu from my C# code behind. I'm adding items through a String foreach Loop. How do I access the dropdown id, since its not displayed in the code behind because it requires ASP controls?

amphetamachine
  • 27,620
  • 12
  • 60
  • 72
MWUser
  • 267
  • 1
  • 7
  • 18

1 Answers1

0

You will need a repeater.

Repeater1.DataSource = yourdatasource
    Repeater1.Databind()


<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate><Ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1"></HeaderTemplate>
<ItemTemplate>

    <li role="presentation">
        <a role="menuitem" href="#"> <%# Eval("yourfieldfromcodebhind here") %> </a>

    </li>
</ItemTemplate>
</asp:Repeater>
causita
  • 1,607
  • 1
  • 20
  • 32
  • This looks good, however I'm trying to add items from a string foreach loop, what changes are required in your solution, mate? – MWUser Mar 13 '15 at 16:07
  • you can create a list of string then while in your loop add to this list. Make the list be the source of your repeater http://www.dotnetperls.com/convert-list-string – causita Mar 13 '15 at 16:14
  • Hello small question, I made the list my data source, but what do I add to the Eval(" ") part of your code? – MWUser Mar 13 '15 at 16:34