Internet Explorer 中的 ASP.NET Dropdownlist 项目列表宽度问题

发布于 2024-10-15 20:46:47 字数 304 浏览 3 评论 0原文

我需要以某种方式修改 ASP.NET dropdownlist 控件,以便在项目列表上具有自动宽度。下拉列表控件本身具有固定宽度且无法更改。

我已经尝试了多种方法,但均无济于事,请参阅http://forums.asp.net/t/ 1648469.aspx

你们中的一些人决定通过构建自定义下拉控件来解决这个问题,但这对于我来说并不是一个真正的选择。

在回答之前,请检查上面链接中的线程,以确保我还没有经历过它。

I need to somehow modify the ASP.NET dropdownlist control to have an auto-width on the items list. The dropdownlist control in itself has a fixed width and that cannot be changed.

I have tried several ways already to no avail, see http://forums.asp.net/t/1648469.aspx

Some of you have decided to solve this issue by building a custom dropdown control, but this is not really an option in my case.

Before answering, please check the thread in the above link to make sure I haven´t been through it already.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只是在用心讲痛 2024-10-22 20:46:47

无法从标准 DDL 控制中获得您所描述的确切行为。最好的办法是在页面上放置一个空白的 DDL,并在其正下方隐藏一个列表框。使用 JavaScript 使列表框出现和消失。您将获得选择,并且 DDL 的宽度不会更改,但列表框宽度可以是动态的。

更好的选择是使用第三方控件集,例如 Telerik 或 ComponentOne,这些控件集已内置此功能。上述建议假设您必须使用内置控件。

There is no way to get the exact behavior your describe out of the standard DDL control. The best bet would be to put a blank DDL on the page with a listbox hidden directly underneath. With JavaScript make the listbox appear and disappear onlick. You'll get selection and the width of the DDL won't change, but the listbox width can be dynamic.

The better option would be to use a third party control set like Telerik or ComponentOne that has this functionality already built into their control set. The above suggestion assumes you have to use built-in controls.

怀念你的温柔 2024-10-22 20:46:47

在网上搜索时,我发现很多人都问过你的问题,并且都得到了与你相同的答案。他们最终接受了残酷的事实,你很快也将不得不接受。

在 IE 中,下拉列表的选项(下拉列表)部分与选择部分(下拉框)大小相同(由于缺乏更好的术语)。您需要调整整个控件的大小,如下所示发布详细信息,或构建自定义 HTML 控件。如果我错了(以及许多其他提供相同解决方案的人),我肯定会第一个承认这一点,但希望似乎很渺茫。

自定义控件不会太困难。在我的脑海中,可能有一个“选择器”div、隐藏的 ol、一些 mouseover/mouseout 事件处理程序,以及一个用于填充列表项的 ASP.NET 中继器。我不会详细介绍实现此自定义控件的细节,因为有很多方法可以实现它。正如 Josh 所说,Telerik 和 ComponentOne 已经实施了这样的控制,但当然是有代价的。如果您愿意,我愿意为您编写一些代码。

In trolling the internet I found that many have asked your question and all received the same answers as you have. They eventually accepted the cold hard truth as you will soon have to as well.

In IE, the options (drop list) section of the drop-down list is the same size as the, for lack of better terms, select portion (drop box). You will either need to resize the entire control, as this post details, or build a custom HTML control. I will most definitely be the first to admit it in the event I am wrong (along with many others that provided the same solution), but hope seems faint.

The custom control would not be TOO extremely difficult. Off the top of my head, maybe a "selector" div, and hidden ol, some mouseover / mouseout event handlers, and an ASP.NET repeater to populate the list items. I won't go into the details of implementing this custom control, because there are many ways you can do it. As Josh stated, Telerik and ComponentOne have already implemented such a control, but of course for a price. If you would like, I would be willing to hack together some code for you.

违心° 2024-10-22 20:46:47

这应该可以解决这个问题,您可以对样式进行任何更改,并且效果完美,包括样式标签并选择我错过的位置:

<style>
.ctrDropDown{
    width:205px;
    font-size:11px;
}
.ctrDropDownClick{
    font-size:11px;
    width:250px;

}
.plainDropDown{
    width:205px;
    font-size:11px;
}
</style>
<div style= "width:205px; overflow:hidden;">
select id="Dropdownlist" class="ctrDropDown"  onblur="this.className='ctrDropDown';" onmousedown="this.className='ctrDropDownClick';" onchange="this.className='ctrDropDown';" >

This should solve it, you could make any changes in the styling and it works perfect, include tags for style and select wherever I missed them:

<style>
.ctrDropDown{
    width:205px;
    font-size:11px;
}
.ctrDropDownClick{
    font-size:11px;
    width:250px;

}
.plainDropDown{
    width:205px;
    font-size:11px;
}
</style>
<div style= "width:205px; overflow:hidden;">
select id="Dropdownlist" class="ctrDropDown"  onblur="this.className='ctrDropDown';" onmousedown="this.className='ctrDropDownClick';" onchange="this.className='ctrDropDown';" >
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文