首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

有没有唯有输入拼音开头字母就能定位的dropdownlist

2013-05-02 
有没有只有输入拼音开头字母就能定位的dropdownlist?本帖最后由 ETJojo 于 2013-04-22 19:04:09 编辑比如

有没有只有输入拼音开头字母就能定位的dropdownlist?
本帖最后由 ETJojo 于 2013-04-22 19:04:09 编辑 比如下拉框有30多个选项,只要输入每个选项的汉字的开头拼音字母,就能快速定位到相应的选项?就像股票软件选股那样的, FTQC  对应 福田汽车
[解决办法]
google "asp.net AutoComplete"
[解决办法]
你的这个功能还多机票网站城市选择都有的....
[解决办法]
你首先需要找一个汉字转拼音的东东
[解决办法]
jquery也可以实现智能提示
http://www.cnblogs.com/kyle_zhao/archive/2010/02/27/1674819.html
[解决办法]


/// <summary>
    /// 拼音工具类
    /// </summary>
    public static class SpellHelper
    {

        /// <summary>
        /// 获取汉字拼音[全拼]
        /// </summary>
        /// <param name="value">汉字串</param>
        /// <returns>返回全拼</returns>
        public static string GetSpell(string value)
        {
            return InnerGetSpell(value);
        }
        /// <summary>
        /// 获取汉字拼音简码[简拼]
        /// </summary>
        /// <param name="value">汉字串</param>
        /// <returns>返回简拼</returns>
        public static string GetSpellFirst(string value)
        {
            return InnerGetSpellFirst(value).ToUpper();
        }


        /// <summary>
        /// 获取拼音
        /// </summary>
        /// <param name="value">汉字串</param>
        /// <param name="spellfirst">输出拼音简码</param>
        /// <returns>返回全拼</returns>
        public static string GetSpell(string value, out string spellfirst)
        {
            spellfirst = InnerGetSpellFirst(value);
            string result = InnerGetSpell(value);
            return result;
        }


        private static string InnerGetSpellFirst(string chineseString)


        {

            String _Temp = null;
            for (int i = 0; i < chineseString.Length; i++)
                _Temp = _Temp + GetOneInnerGetSpellFirst(chineseString.Substring(i, 1));
            return _Temp;
        }

        /// <summary>
        /// 单个汉字
        /// </summary>
        /// <param name="OneIndexTxt">汉字</param>
        /// <returns>首拼</returns>
        private static String GetOneInnerGetSpellFirst(String OneIndexTxt)
        {
            if (Convert.ToChar(OneIndexTxt) >= 0 && Convert.ToChar(OneIndexTxt) < 256)
                return OneIndexTxt;
            else
            {
                Encoding gb2312 = Encoding.GetEncoding("gb2312");
                byte[] unicodeBytes = Encoding.Unicode.GetBytes(OneIndexTxt);
                byte[] gb2312Bytes = Encoding.Convert(Encoding.Unicode, gb2312, unicodeBytes);
                if (gb2312Bytes.Length >= 2 && gb2312Bytes[0] > 160 && gb2312Bytes[1] > 160)
                {
                    return GetX(Convert.ToInt32(
                    String.Format("{0:D2}", Convert.ToInt16(gb2312Bytes[0]) - 160)
                    + String.Format("{0:D2}", Convert.ToInt16(gb2312Bytes[1]) - 160)
                    ));
                }
                else return string.Empty;
            }
        }


        /// <summary>
        /// 根据区位得到首字母
        /// </summary>
        /// <param name="GBCode">区位</param>


        /// <returns></returns>
        private static String GetX(int GBCode)
        {
            if (GBCode >= 1601 && GBCode < 1637) return "a";
            if (GBCode >= 1637 && GBCode < 1833) return "b";
            if (GBCode >= 1833 && GBCode < 2078) return "c";
            if (GBCode >= 2078 && GBCode < 2274) return "d";
            if (GBCode >= 2274 && GBCode < 2302) return "e";
            if (GBCode >= 2302 && GBCode < 2433) return "f";
            if (GBCode >= 2433 && GBCode < 2594) return "g";
            if (GBCode >= 2594 && GBCode < 2787) return "h";
            if (GBCode >= 2787 && GBCode < 3106) return "j";
            if (GBCode >= 3106 && GBCode < 3212) return "k";
            if (GBCode >= 3212 && GBCode < 3472) return "l";
            if (GBCode >= 3472 && GBCode < 3635) return "m";
            if (GBCode >= 3635 && GBCode < 3722) return "n";
            if (GBCode >= 3722 && GBCode < 3730) return "o";
            if (GBCode >= 3730 && GBCode < 3858) return "p";
            if (GBCode >= 3858 && GBCode < 4027) return "q";
            if (GBCode >= 4027 && GBCode < 4086) return "r";
            if (GBCode >= 4086 && GBCode < 4390) return "s";
            if (GBCode >= 4390 && GBCode < 4558) return "t";
            if (GBCode >= 4558 && GBCode < 4684) return "w";
            if (GBCode >= 4684 && GBCode < 4925) return "x";


            if (GBCode >= 4925 && GBCode < 5249) return "y";
            if (GBCode >= 5249 && GBCode <= 5589) return "z";
            if (GBCode >= 5601 && GBCode <= 8794)
            {

                String _gbcode = GBCode.ToString();
                int pos = (Convert.ToInt16(_gbcode.Substring(0, 2)) - 56) * 94 + Convert.ToInt16(_gbcode.Substring(_gbcode.Length - 2, 2));
                return CodeData.Substring(pos - 1, 1);
            }
            return " ";
        }


        /// <summary>
        /// 获取汉字的全拼音
        /// </summary>
        /// <param name="x">传汉字的字符串</param>
        /// <returns>汉字的字符串的拼音</returns>
        public static string InnerGetSpell(string x)
        {
            byte[] B = new byte[2];
            string s = "";
            char[] c = x.ToCharArray();
            for (int j = 0; j < c.Length; j++)
            {
                B = System.Text.Encoding.Default.GetBytes(c[j].ToString());
                if ((int)(B[0]) <= 160 && (int)(B[0]) >= 0)
                {
                    s += c[j];
                }
                else
                {
                    for (int i = (iAFull.Length - 1); i >= 0; i--)
                    {
                        if (iAFull[i] <= (int)(B[0]) * 256 + (int)(B[1]) - 65536)


                        {
                            s += GetFirstToUpper(sAFull[i]);
                            break;
                        }
                    }
                }
            }
            return s;
        }

        /// <summary>
        /// 将输入的字符串的第一个字母大写并输出
        /// </summary>
        /// <param name="instr"></param>
        /// <returns></returns>
        private static string GetFirstToUpper(string instr)
        {
            if (instr.Length > 1)
            {
                return (instr.Substring(0, 1)).ToUpper() + instr.Substring(1);
            }
            else
            {
                return instr.ToUpper();
            }
        }


       

热点排行