2

I have dropdownlist controls which are populated from database. I want to apply bootstrap dropdownlist effect to it. How can I do it. I tried form-control but only the dropdown control changes and it is not like a BS dropdown, the list is the same as the one in asp.net.

The second image is what I want. and the first one is I get when I apply form control

Code:

  <asp:DropDownList ID="ddlCType" runat="server" CssClass="form-control" DataSourceID="SqlDataSource1" DataTextField="Comp_Type" DataValueField="Type_ID"  AutoPostBack="True" OnDataBound="DDLCTypeDataBound" Style="width: 400px">

Current Dropdownlist

I want it to be like this

5
  • 1
    You have two images of drop downs. Which one is what you want? Which one do you currently get when applying form-control class? Commented Jan 28, 2016 at 18:25
  • The second one is what I want. and the first one is I get when I apply form control Commented Jan 28, 2016 at 18:32
  • The first one is what the bootstrap drop downs look like. I'm not sure what the 2nd one is. It looks like it something else or has some special CSS applied to it. Commented Jan 28, 2016 at 18:35
  • 1
    2nd one possibly jQuery UI: jqueryui.com/selectmenu Commented Jan 28, 2016 at 18:35
  • The list should look like this: how to do this : w3schools.com/bootstrap/… Commented Jan 28, 2016 at 18:38

1 Answer 1

5

It seems the bootstrap 3 is not able to pick 'form-control' from the rendered html from asp.net engine. So here are the options.

Option 1 : Assign the class during page load.

<script>
    $().ready(function(){
    $('#<%=ddlCType.ClientID%>').addClass("form-control");
    });
</script>

Option 2 : : Use bootstrap-select plugin.

<asp:DropDownList ID="ddlCType" runat="server" CssClass="selectpicker" DataSourceID="SqlDataSource1" DataTextField="Comp_Type" DataValueField="Type_ID"  AutoPostBack="True" OnDataBound="DDLCTypeDataBound" Style="width: 400px">

<script>
$().ready(function(){
$('#<%=ddlCType.ClientID%>').selectpicker();
});
</script>

Example : http://jsfiddle.net/DinoMyte/wd1z0zmg/8/

Sign up to request clarification or add additional context in comments.

2 Comments

I face the same problem in option 1 .. the form control does not apply to list items. I want the list items to look like this: w3schools.com/bootstrap/…
try option2 then. I wasn't sure about option 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.