在此演示中,我只是用实际渲染的HTML替换了ASP.NET代码,并且表现正确。
因此,如果您仍然遇到了您描述的问题,我必须说罪魁祸首超出了您到目前为止的共享。
.input-group .form-control {
height: 34px;
border-radius: 0;
}
.input-group-addon .form-control {
height: 34px;
border-radius: 0;
}
.cust-addon {
padding: 0px !important;
}
.Select2-fixed-width+.select2-container {
display: block !important;
width: 200px !important;
font-size: 12px !important;
}
<!-- added jQuery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
<script>
$(document).ready(function() {
$(".searchfilter").select2();
});
</script>
<!-- I expanded your code to mimic real rendered html -->
<span class="input-group-addon p-0 cust-addon">
<!-- Here I added the searchfilter class since that's the selector you used to init the select2 -->
<select class="searchfilter form-control Select2-fixed-width">
<option value="">Please Select</option>
<option value="+1">+1 (United States)</option>
<option value="+44">+44 (United Kingdom)</option>
<option value="+91">+91 (India)</option>
<option value="+33">+33 (France)</option>
<option value="+49">+49 (Germany)</option>
</select>
</span>