增加下拉列表的宽度

时间:2009-11-02 13:21:45

标签: .net asp.net drop-down-menu asp.net-controls

如何在ASP.NET中增加DropDownList的宽度?

4 个答案:

答案 0 :(得分:1)

您可以在.CSS文件中,内联或使用STYLE标记执行此操作。您也可以通过设置属性(DropDownList1.Attribute.Add(“style”,“etc ...”))在代码隐藏中执行此操作。

<强> CSS:

.ChangeWidth
{
    width:400px;    
}

<强>标记:

<asp:DropDownList ID="DropDownList1" CssClass="ChangeWidth" runat="server">
</asp:DropDownList>

答案 1 :(得分:0)

我建议您使用动态宽度,如下所示:

<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>

并使用它:onclick="autoWidth()"

答案 2 :(得分:0)

<asp:DropDownList ID="DropDownList1" width="50px" runat="server"> 
</asp:DropDownList> 

答案 3 :(得分:0)

您可以通过给出来增加DropDownList的宽度  <asp:DropDownList ID="DropDownList1" width="50px" runat="server" width="100px"> </asp:DropDownList> 或者通过定义css文件 `.Drop

{ 宽度:100像素; }`