如何使下拉列表显示选定的值在下拉而不是底部? [英] How to make a dropdownlist show selected value at top of dropdown instead of bottom?

查看:251
本文介绍了如何使下拉列表显示选定的值在下拉而不是底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:这发生在Chrome但不是IE

This happens in Chrome but not IE

这是一个愚蠢,无用的小问题,但我有一个客户询问是否可能。 SO,它杀了我现在知道。

This is such a silly, useless little question but I have a client asking if the following is possible. SO, it's killing me to know now.

我在使用C#代码隐藏的aspx页面中创建了一个DropDownList(但是,为了简化我的问题,我的示例没有代码隐藏)。

I have created a DropDownList in an aspx page that is using C# code-behind (however, my example here has no code-behind for simplicity of stating my question).

查看我的示例DropDownList。我在此列表中有46个选项,请参阅 A B 。假设用户选择列表中间范围内的项目(参见: C )。当用户返回到DropDown时,它会在底部显示所选的值(请再次参阅 C )。

See my example DropDownList. I have 46 options in this list see: A and B. Assume user selects an item in the mid-range of the list - (see: C). When the user goes back into the DropDown, it shows the selected value at the bottom (see: C again).

以告诉\强制DropDownList在可用值列表的 TOP 中显示所选索引\ value \ item(参见: D )?

Is there a way to tell \ force a DropDownList to display the selected index \ value \ item at the TOP of the available values list (see: D)?

此示例使用非常简单的代码:

This example is using very plain code:

<asp:UpdatePanel ID="DropDownTestUpdatePanel" runat="server">
    <ContentTemplate>    
        <asp:Panel id="DropDownTestPanel" runat="server">
            <asp:DropDownList id="ColorList"
                AutoPostBack="True"
                runat="server">
                <asp:ListItem Value="1 ">  1 </asp:ListItem>
                <asp:ListItem Value="2 ">  2 </asp:ListItem>
                <asp:ListItem Value="3 ">  3 </asp:ListItem>
                <asp:ListItem Value="4 ">  4 </asp:ListItem>
                <asp:ListItem Value="5 ">  5 </asp:ListItem>
                <asp:ListItem Value="6 ">  6 </asp:ListItem>
                <asp:ListItem Value="7 ">  7 </asp:ListItem>
                <asp:ListItem Value="8 ">  8 </asp:ListItem>
                <asp:ListItem Value="9 ">  9 </asp:ListItem>
                <asp:ListItem Value="0 ">  0 </asp:ListItem>
                <asp:ListItem Value="10"> 10 </asp:ListItem>
                <asp:ListItem Value="11"> 11 </asp:ListItem>
                <asp:ListItem Value="12"> 12 </asp:ListItem>
                <asp:ListItem Value="13"> 13 </asp:ListItem>
                <asp:ListItem Value="14"> 14 </asp:ListItem>
                <asp:ListItem Value="15"> 15 </asp:ListItem>
                <asp:ListItem Value="16"> 16 </asp:ListItem>
                <asp:ListItem Value="17"> 17 </asp:ListItem>
                <asp:ListItem Value="18"> 18 </asp:ListItem>
                <asp:ListItem Value="19"> 19 </asp:ListItem>
                <asp:ListItem Value="20"> 20 </asp:ListItem>
                <asp:ListItem Value="21"> 21 </asp:ListItem>
                <asp:ListItem Value="22"> 22 </asp:ListItem>
                <asp:ListItem Value="23"> 23 </asp:ListItem>
                <asp:ListItem Value="24"> 24 </asp:ListItem>
                <asp:ListItem Value="25"> 25 </asp:ListItem>
                <asp:ListItem Value="26"> 26 </asp:ListItem>
                <asp:ListItem Value="27"> 27 </asp:ListItem>
                <asp:ListItem Value="28"> 28 </asp:ListItem>
                <asp:ListItem Value="29"> 29 </asp:ListItem>
                <asp:ListItem Value="30"> 30 </asp:ListItem>
                <asp:ListItem Value="31"> 31 </asp:ListItem>
                <asp:ListItem Value="32"> 32 </asp:ListItem>
                <asp:ListItem Value="33"> 33 </asp:ListItem>
                <asp:ListItem Value="34"> 34 </asp:ListItem>
                <asp:ListItem Value="35"> 35 </asp:ListItem>
                <asp:ListItem Value="36"> 36 </asp:ListItem>
                <asp:ListItem Value="37"> 37 </asp:ListItem>
                <asp:ListItem Value="38"> 38 </asp:ListItem>
                <asp:ListItem Value="39"> 39 </asp:ListItem>
                <asp:ListItem Value="40"> 40 </asp:ListItem>
                <asp:ListItem Value="41"> 41 </asp:ListItem>
                <asp:ListItem Value="42"> 42 </asp:ListItem>
                <asp:ListItem Value="43"> 43 </asp:ListItem>
                <asp:ListItem Value="44"> 44 </asp:ListItem>
                <asp:ListItem Value="45"> 45 </asp:ListItem>
                <asp:ListItem Value="46"> 46 </asp:ListItem>
           </asp:DropDownList>
        </asp:Panel>     
    </ContentTemplate>
</asp:UpdatePanel>     

我已经搜索和搜索...并在线搜索答案。

I have searched and searched... and searched online for answers. But it is hard to find an answer to a question when you cannot phrase it well.

非常感谢您提供任何帮助。

Thank you all in advance for any help you might offer.

为了清楚起见,编辑以改写:
假设你是一个整天使用一个DropDownList的用户。例如,您可以从按顺序列出的客户编号中获取订单(参见:上图)。每次你移动到你的下一个订单,你必须去点击DropDownList中的客户编号。好吧,一旦你到达客户#20(见上面的 A ),你现在必须点击下拉并滚动\移动\点击下一个获得下一个号码。 (我知道,我知道,它的设置专注于负载,所以一个人真的可以用箭头键或键入移动列表,但...是一个客户 - whaddya想要更快)。

无论如何,您可以看到,当您点击它以选择您的下一个客户时,让DropDownList的行为像上面的 D ,而不是 C 会更有利。 / p>

Editing to rephrase for clarity sake: Pretend you're a user who works with one DropDownList all day long. For example, you get orders from customer numbers that are listed in order (see: image above). Each time you move to your next order, you have to go click on the customer number in the DropDownList. Well, once you get to customer #20 (see A above), you now have to click the DropDown and scroll \ move \ click down one to get your next number. (I know, I know, it's set to focus on load so one could really be faster with arrow keys or typing to move the list but ... it's a customer - whaddya want?).
Anyway, you can see how it would be more beneficial to have the DropDownList behave like D above rather than C above when you go click on it to select your next customer, right?

推荐答案

我有一个类似的问题。这解决了我的问题:

I had a similar problem. This fixed my issue:

protected void Page_PreRender(object sender, EventArgs e)
{
    var itemIndex = DropDownList1.SelectedIndex;
    var item = DropDownList1.Items[itemIndex];
    DropDownList1.Items.RemoveAt(itemIndex);
    DropDownList1.Items.Insert(0, new ListItem(item.Text, item.Value));
}

资料来源:

如何通过使用C#.net 将选定的下拉列表值移动到项目列表的第一位置

How to move selected value of drop down list to first position in the list of items by using C#.net

这篇关于如何使下拉列表显示选定的值在下拉而不是底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆