How can I increase the width of a DropDownList in ASP.NET?
A:
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
2009-11-02 13:27:11
select1 is the dropdown value is it?
2009-11-02 13:29:00
Yes, of course it is.
Nathan Campos
2009-11-02 13:31:34
Onclick event of dropdown? its says there is no onclick event for dropdown..or its a updatepanel onclick event?
2009-11-02 13:36:27
It's just an example, I use it for other things.
Nathan Campos
2009-11-02 14:37:48
+2
A:
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
2009-11-02 14:27:47
Make 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
Serg
2010-09-01 13:54:33
A:
<asp:DropDownList ID="DropDownList1" width="50px" runat="server">
</asp:DropDownList>
kralco626
2010-09-01 13:52:47