Csharp:jquery.ajax-combobox

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>JS object instead of DB: jquery.ajax-combobox</title>
<link rel="stylesheet" href="js/jquery.ajax-combobox.css"/>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.ajax-combobox.min.js"></script>
<script type="text/javascript">
/*
https://github.com/sutara79/jquery.ajax-combobox
https://plugins.jquery.com/ajax-combobox/
https://sutara79-php.herokuapp.com/demo/jquery.ajax-combobox/
  var items = [];
  $.each( data, function( key, val ) {
    items.push( "<li id='" + key + "'>" + data[0].CountyCode + "</li>" );
  });
  
  $( "<ul/>", {
    "class": "my-new-list",
    html: items.join( "" )
  }).appendTo( "body" );
  */ 
var data;
$.getJSON( "AjaxComboxHandler.ashx", function(data){
   $('#foo').ajaxComboBox(
    data,
    {
      lang: 'hk',
      navi_num: 5, //显示几个数字页码
      per_page: 15,//每页显示多少条
      db_table: 'nation',
      field: 'name',
      sub_info: true,
      show_field:'CountyCode,name,HkName,EnName,CnName,position,IdOrder',//提示可以显示的字段
      sub_as: {
        CountyCode: '國際區號:', //提示显示的列名
        HkName:'繁体中文名:',
        EnName: '英文名:',
        CnName:'简体中文名:',       
        position: '所在洲:',
        IdOrder:'排序:',//字符串排序
 
      },
      select_only: true,
      init_record: '00',
      primary_key: 'CountyCode',
      order_by: [
      'IdOrder ASC', // ASC or DESC
      'CountyCode'
      ]
    }
  
  );
});
  
</script>
</head>
<body>
<h1>JS object instead of DB: jquery.ajax-combobox</h1>
<form id="Form1" action="" runat="server">
 <label for="foo">國家:</label><br>
<asp:TextBox ID="foo" CssClass="foo" runat="server"></asp:TextBox>
 <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" onClick="this.setSelectionRange(0, this.value.length)/>
</form>
</body>
</html>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/// <summary>
 /// $codebehindclassname$ 的摘要说明
 /// 塗聚文  涂聚文  Geovin Du
 /// 2019-7-22
 /// </summary>
 [WebService(Namespace = "http://tempuri.org/")]
 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
 public class AjaxComboxHandler : IHttpHandler
 {
     CountyTelCodeBLL telbll = new CountyTelCodeBLL();
     /// <summary>
     ///
     /// </summary>
     /// <param name="context"></param>
     public void ProcessRequest(HttpContext context)
     {
         context.Response.ContentType = "text/plain";
 
         List<EntityCounty> list = new List<EntityCounty>();
         CountyTelCode code = new CountyTelCode();
         //code.TelData().DefaultView.Sort = "IdOrder asc";
         //DataRow[] drs = code.TelData().Select("", "IdOrder asc");
 
         DataTable dt = telbll.SelectCountyTelCodeDataTableAll();
 
         foreach (DataRow row in dt.Rows)  //code.TelData().Rows
         {
             EntityCounty ec = new EntityCounty();
             ec.CountyCode = row["TelCoutyCode"].ToString().Trim();
             ec.name = row["SimpleNameHK"].ToString().Trim();
             ec.HkName = row["SimpleNameHK"].ToString().Trim();
             ec.CnName = row["SimpleNameCN"].ToString().Trim();               
             ec.EnName = row["SimpleNameEN"].ToString().Trim();
             ec.position = row["Continent"].ToString().Trim();
             ec.IdOrder = row["IdOrder"].ToString().Trim();
             list.Add(ec);
         }
         //序列化 JavaScriptSerializer
         JavaScriptSerializer jss = new JavaScriptSerializer();
         string str = jss.Serialize(list);
         //返回
         context.Response.Write(str);       
 
 
          
     }
 
     public bool IsReusable
     {
         get
         {
             return false;
         }
     }
     /// <summary>
     ///
     /// </summary>
     /// <param name="jsonData"></param>
     /// <returns></returns>
     private Dictionary<string, object> JsonToDictionary(string jsonData)
     {
         //实例化JavaScriptSerializer类的新实例
         JavaScriptSerializer jss = new JavaScriptSerializer();
         try
         {
             //将指定的 JSON 字符串转换为 Dictionary<string, object> 类型的对象
             return jss.Deserialize<Dictionary<string, object>>(jsonData);
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message);
         }
     }
 }
 
 /// <summary>
 ///
 /// </summary>
 public class EntityCounty
 {
 
     private string _CountyCode;
   
     /// <summary>
     ///    [ScriptIgnore] 为不显示
     /// </summary>
     public string CountyCode
     {
         get { return _CountyCode; }
         set { _CountyCode = value; }
     }
 
     private string _name;
     /// <summary>
     ///
     /// </summary>
     public string name
     {
         get { return _name; }
         set { _name = value; }
     }
     private string _EnName;
     /// <summary>
     ///
     /// </summary>
     public string EnName
     {
         get { return _EnName; }
         set { _EnName = value; }
     }
 
     private string _CnName;
     /// <summary>
     ///
     /// </summary>
     public string CnName
     {
         get { return _CnName; }
         set { _CnName = value; }
     }
     private string _HkName;
     /// <summary>
     ///
     /// </summary>
     public string HkName
     {
         get { return _HkName; }
         set { _HkName = value; }
     }
     private string _position;
     /// <summary>
     ///
     /// </summary>
     public string position
     {
         get { return _position; }
         set { _position = value; }
     }
 
     private string _IdOrder;
     /// <summary>
     ///
     /// </summary>
     public string IdOrder
     {
         get { return _IdOrder; }
         set { _IdOrder = value; }
     }
 }

  

posted @   ®Geovin Du Dream Park™  阅读(421)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2015-07-10 csharp: Export DataSet into Excel and import all the Excel sheets to DataSet
2007-07-10 70个流行的AJAX应用的演示和源码下载
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示