Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Friends. I am doing a project in ASP.Net using Bootstrap. I have a table called M_State. I need to bind the state names into bootstrap dropdown. Is it possible to bind values from database in to Bootstarp dropdown?? Kindly help me
Posted

1 solution

You can do this way


C#
void BindDrowpodown()
  {
      var list = new List<keyvaluepair><string,>>();
      list.Add(new KeyValuePair<string,>("http://www.google.com", "a"));
      list.Add(new KeyValuePair<string,>("http://www.google.com", "b"));
      list.Add(new KeyValuePair<string,>("http://www.google.com", "c"));

      string drowdownhtml = string.Empty;

      foreach (var element in list)
      {
          drowdownhtml += " <ul><li><a href=" + element.Key + ">" + element.Value + "</a></li></ul>";
      }

      lrtValues.Text = drowdownhtml;





  }</keyvaluepair>


In aspx page
ASP.NET
<div class="dropdown">
                <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">
                    Dropdown Example
  <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    <asp:Literal ID="lrtValues" runat="server"></asp:Literal>
                </ul>
            </div>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900