How can I increase the width of a DropDownList in ASP.NET?
Asked
Active
Viewed 6,948 times
4 Answers
1
You can do this in a .CSS file, inline or with a STYLE tag. You can also do it in the code-behind by setting attributes(DropDownList1.Attribute.Add("style","etc...")).
CSS:
.ChangeWidth
{
width:400px;
}
Markup:
<asp:DropDownList ID="DropDownList1" CssClass="ChangeWidth" runat="server">
</asp:DropDownList>

rick schott
- 21,012
- 5
- 52
- 81
-
i did as you said; there is no change at alll – Nov 02 '09 at 15:06
-
1Make you sure you rebuild your application and whilst in the browser press Ctrl+F5 to load your current CSS file. Cache is ***** like that. :P – Sep 01 '10 at 13:54
0
I suggest you to use a dynamic width, like this:
<script type="text/javascript">
function autoWidth()
{
var maxlength = 0;
var mySelect = document.getElementById('Select1');
for (var i=0; i<mySelect.options.length;i++)
{
if (mySelect[i].text.length > maxlength)
{
maxlength = mySelect[i].text.length;
}
}
mySelect.style.width = maxlength * 10;
}
</script>
And use it like this: onclick="autoWidth()"

Nathan Campos
- 28,769
- 59
- 194
- 300
-
-
Onclick event of dropdown? its says there is no onclick event for dropdown..or its a updatepanel onclick event? – Nov 02 '09 at 13:36
-
0
You can increase the width of a DropDownList by giving
<asp:DropDownList ID="DropDownList1" width="50px" runat="server" width="100px">
</asp:DropDownList>
Or by defining the css file
`.Drop
{ width:100px; }`

Vinoth Narayan
- 275
- 2
- 15
0
<asp:DropDownList ID="DropDownList1" width="50px" runat="server">
</asp:DropDownList>

kralco626
- 8,456
- 38
- 112
- 169