【ASP.NET】ドロップダウンリストの幅・高さを変える方法

スポンサーリンク

ASP.NETのドロップダウンリストの幅と高さを変える方法です。

デフォルトだと、以下のように幅は選択肢の中の一番長いもの、高さは文字のサイズに合わせられています。

変え方

①aspxファイルで変える方法

以下のように、asp:DropDownListのタグに、「Width=”100px” Height=”100px”」というように指定する。
※%指定が良い場合は、「Width=”100%” Height=”100%“」とすればよい。

<asp:DropDownList ID="DropDownList1" runat="server" Width="100px" Height="100px">
    <asp:ListItem Value="1">あああああああああああ</asp:ListItem>
    <asp:ListItem Value="2">いいい</asp:ListItem>
    <asp:ListItem Value="3">う</asp:ListItem>
</asp:DropDownList>

以下のようになります。

②コードで変える方法

aspx.csファイルで以下のように記載する。

DropDownList1.Width = 100; // デフォルトでpx変換される
// DropDownList1.Width = Unit.Percentage(100); 幅を%で指定したい場合
DropDownList1.Height = 100; // デフォルトでpx変換される
// DropDownList1.Height = Unit.Percentage(100); 高さを%で指定したい場合

①と同じように以下のようになる。

コメント

タイトルとURLをコピーしました