如何使在下拉列表,而不是底部的顶部选定值一个DropDownList节目? [英] How to make a dropdownlist show selected value at top of dropdown instead of bottom?

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

问题描述

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

This happens in Chrome but not IE

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

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#code-背后的一个aspx页面一个DropDownList(但是,我这里举例没有code-背后,说明我的问题简单)。

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 。假设用户选择列表中的中档项目 - (见: C )。不过当用户回到下拉列表中,它显示在底部选择的值(参见: 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显示所选指标\\值\\项目的可用值列表(见: 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)?

此示例是使用很平淡code:

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.

编辑以另一种方式为清楚起见:
pretend你是谁一个DropDownList的整天工作的用户。例如,你从顺序列出客户数量的订单(参见:上图)。每次移动到下一个订单的时候,你必须去点击在DropDownList客户编号。那么,一旦你的客户#20(参见 A 以上),你现在必须单击下拉和滚动\\移动\\点击向下,让您的下一个号码。 (我知道,我知道,它的设置侧重于负载,以便人们可以真正更快使用箭头键来打字或移动的清单,但...这是一个客户 - 那么,有什么希望?)结果。
无论如何,你可以看到它是如何更有利于有DropDownList的行为像 D 上面,而不是 C 上面,当你去点击它,选择你的下一个客户,右?

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));
}

来源:

<一个href=\"http://forums.asp.net/t/1926286.aspx?How%20to%20move%20selected%20value%20of%20drop%20down%20list%20to%20first%20position%20in%20the%20list%20of%20items%20by%20using%20C%20net\"相对=nofollow>如何通过使用移动列表下拉到第一位置的项目列表中选择值C#.NET

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

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