Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

widen dropdownlist when I click down arrow on control

Status
Not open for further replies.

MzKitty

Programmer
Oct 28, 2003
254
US
Hi. I'm using vs2008 and vb.net. I have a dropdownlist on my web page that is 500px wide. When the user clicks on the dropdown arrow, I want to change the width to auto. There is no onclick event for the asp dropdownlist and I don't know how to capture the click so I can widen the field.

Here's my code on my dropdownlist:
<asp:DropDownList ID="dropCustID" runat="server"
AppendDataBoundItems="True" AutoPostBack="True" Height="25px" OnSelectedIndexChanged="dropCustID_SelectedIndexChanged"
style="font-size: small; font-family: 'Courier New', Courier, monospace;" TabIndex="1">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>

I've searched all over the web and am hoping that someone can help me out with this.

Thanks
Cathy
 
this is a client side issue so you will resolve this using css, javascript or a combination of both. If you set the width of the control (either directly or indirectly) than that is the how wide the control will be. if you don't set the width the control will default to the width of the widest option.

if you want the selection to be static width but the options to be dynamic, then you cannot use the dropdownlist control. instead you will need to use some javascript/css/html "magic" to make the control appear like a drop down. jquery's autocomplete is the best option for this scenario

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
I've never used jquery, but I'll look at anything right now. I don't know why they would not have a onclick event available on the control, but I hope they fix it! Thanks Jason, I'll check it out.

Cathy
 
there is an onchange event in javascript and there is a selectedindexchanged event in webforms. if you want to postback when the index changes then you need to set autopostback=true.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
I'm using the selectindexedchanged event already. In fact on it, I have set the width back to 500px from auto. I'll look into the onChange event and see if I can use it as a trigger.

Cathy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top