Reputation: 1779
I have a dropdown list box that displays data from my database. Problem is that some records are quite long so the width of the dropdown box extends past the side of my screen. I have a reasonible width set but it is not stopping the dropdown box from getting as wide as it needs to display each record. How can I set a fixed width on this?
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource1Usage" DataTextField="data_text"
DataValueField="ID" Width="280px">
</asp:DropDownList>here
Thanks,
Upvotes: 5
Views: 31210
Reputation: 9092
try to set the style as follows:
<select id="yourselect" style="width: 100px; max-width: 100px">
<option>...</option>
</select>
or
<div style="width: 100px; max-width: 100px">
<select id="yourselect" style="width: 100%; position: relative">
<option>...</option>
</select>
</div>
Maybe this helps...
Edit: Using the Attributes property:
markup:
<asp:DropDownList ID="cboItems" runat="server" />
Code behind:
List<ListItem> items = new List<ListItem>();
for (int i = 1; i < 11; i++)
{
ListItem item = new ListItem();
item.Text = string.Format("this is a very very long item text corresponding to the number {0}", i);
item.Value = i.ToString();
items.Add(item);
}
cboItems.DataSource = items;
cboItems.DataBind();
// after data bind is complete
cboItems.Attributes["style"] = "width: 100px; max-width: 100px";
Maybe i didn't understand what you're trying to do, but this is what I meant with attributes.
Upvotes: 4
Reputation: 9153
have a look at css options
#myselect {
width:230px;
}
#myselect option {
width:220px;
}
more is here:
http://www.webmasterworld.com/html/3018783.htm
the answer i thing you want is by penders
Upvotes: 4
Reputation: 2002
You can use CSS. Define style with fixed width and use it while creating dropdown box.
Upvotes: 0