In the last article 《EXT.NET Efficient development ( One )—— summary 》 in , Give a general introduction to EXT.NET. Then this article will continue to complete the unfinished business . When it comes to efficient development , That is, the eight immortals cross the sea to show their magic power . Like using a code generator , You can refer to my post for this 《CodeSmith series ( 3、 ... and )—— Use CodeSmith Generate ASP.NET page 》. I am more respected mass production . Of course , This is not the point of this article , Anyone who has seen the title knows .

In the use of EXT.NET When ( Of course, it's not just EXT.NET), There's always a lot of repetition , So encapsulating some practical functions can be done once and for all .

1) Radio and check boxes .

Look at the picture and start talking , Pictured

When choosing something else , Go out of the box and fill in the data . In real demand , A lot of options are not just A、B、C、D, You can often customize it yourself . In the face of this demand , It's troublesome and inconvenient to add a frame every time , So we adhere to the principle of not building wheels repeatedly , The following functions are defined :

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
/// <summary>
/// Bind radio box groups ( The last item is an editable item , Keep the position at ID+Hidden)
/// </summary>
/// <typeparam name="T"> Class types </typeparam>
/// <param name="lst"> Generic set </param>
/// <param name="ID"> Check box group ID</param>
/// <param name="TextPropertyName"> The name of the text property field to be bound ( Capital letters and small letters must be the same )</param>
/// <param name="ValuePropertyName"> The name of the value property field that needs to be bound ( Capital letters and small letters must be the same )</param>
/// <param name="CheckedPropertyName"> The field name of the selection property to be bound ( Capital letters and small letters must be the same )</param>
/// <param name="isCheckedPropertyName"> Whether to select the property field name , If such as false, be CheckedPropertyName Represents the selected value </param>
/// <param name="_ColumnsNumber"> Show the number of columns </param>
/// <param name="_remark"> Note item name , If this item is set , You can fill in the remark </param>
/// <param name="textlen"> The length of the text displayed </param>
public  static  void  BindRadioGroup<T>(System.Web.UI.UserControl _userControl, List<T> lst, string  ID, string  TextPropertyName, string  ValuePropertyName, string  CheckedPropertyName, bool  isCheckedPropertyName, int ? _ColumnsNumber, string  _remark, int  textlen)
{
     if  (lst != null  && lst.Count > 0)
     {
         Control _control = _userControl.FindControl(ID);
         if  (_control is  RadioGroup)
         {
             // The script realizes the pop-up box to fill in other items , Here are the parameters
             //hiddenID: Where the text of other items is saved ID
             //chk: Other items of CheckBox
             //orgBoxLabel: The original BoxLabel
             string  _setRemarkScript =
             @"
                         function setChkRemark(hiddenID, chk, orgBoxLabel ,textlen) {
                             if (chk.getValue()) {
                                 Ext.MessageBox.show({
                                     title: orgBoxLabel,
                                     msg: ' Please enter ' + orgBoxLabel + ':',
                                     width: 300,
                                     buttons: Ext.MessageBox.OKCANCEL,
                                     multiline: true,
                                     value: hiddenID.getValue(),
                                     fn: function (btn, text) {
                                         var remark = text.replace(/(^\s*)|(\s*$)/g, '');
                                         if (btn == 'cancel')
                                             Ext.MessageBox.alert(' reminder ', ' Operation cancelled .');
                                         else if (btn == 'ok') {
                                             hiddenID.setValue(remark);
                                             if (remark!='')
                                                 chk.setBoxLabel(orgBoxLabel+':'+(remark.length>textlen? remark.toString().substring(0,textlen)+'...':remark));
                                             else
                                                 chk.setBoxLabel(orgBoxLabel);
                                         }
                                     }
                                 });
                             }
                         }
             " ;
             // Register function
             _userControl.Page.ClientScript.RegisterStartupScript(_userControl.GetType(), "setChkRemark" , _setRemarkScript, true );
             RadioGroup groupRadios = _control as  RadioGroup;
             if  (groupRadios == null )
                 return ;
             //groupRadios.SubmitValue = true;
             #region 【_ColumnsNumber】 Set the number of display columns , by null One line shows 4 Column .
             _ColumnsNumber = _ColumnsNumber ?? 4;
             if  (lst.Count <= _ColumnsNumber)
             {
                 groupRadios.ColumnsNumber = lst.Count;
             }
             else
             {
                 groupRadios.ColumnsNumber = _ColumnsNumber.Value;
             }
             #endregion
             groupRadios.Items.Clear();
             int  i = 0;
             foreach  ( var  item in  lst)
             {
                 T t = item;
                 Type type = t.GetType();
                 Radio rdo = new  Radio();
                 rdo.ID = string .Format( "{0}items{1}" , ID, i);
                 PropertyInfo TextProInfo = type.GetProperty(TextPropertyName);
                 if  (TextProInfo == null )
                     ExtensionMethods.ThrowNullException(type, TextPropertyName);
 
                 PropertyInfo ValueProInfo = type.GetProperty(ValuePropertyName);
                 if  (ValueProInfo == null )
                     ExtensionMethods.ThrowNullException(type, ValuePropertyName);
 
                 object  objText = TextProInfo.GetValue(t, null );
                 rdo.BoxLabel = objText == null  ? string .Empty : objText.ToString();
                 object  objValue = ValueProInfo.GetValue(t, null ).ToString();
                 rdo.Tag = objValue == null  ? string .Empty : objValue.ToString();
                 rdo.InputValue = objValue == null  ? string .Empty : objValue.ToString();
                 if  (!isCheckedPropertyName)
                 {
                     if  (rdo.Tag == CheckedPropertyName)
                         rdo.Checked = true ;
                     groupRadios.Items.Add(rdo);
                     i++;
                     continue ;
                 }
                 PropertyInfo CheckedProInfo = type.GetProperty(CheckedPropertyName);
                 if  (CheckedProInfo == null )
                     ExtensionMethods.ThrowNullException(type, CheckedPropertyName);
                 if  ((CheckedProInfo.GetValue(t, null ) ?? 0).ToString() == "1" )
                     rdo.Checked = true ;
                 groupRadios.Items.Add(rdo);
                 i++;
             }
             groupRadios.Items[groupRadios.Items.Count - 1].Listeners.Check.Handler = "setChkRemark(#{" + ID + "Hidden},this,'"  + _remark + "',"  + textlen + ");" ;
         }
         else  if  (_control is  System.Web.UI.WebControls.RadioButtonList)
         {
             System.Web.UI.WebControls.RadioButtonList _rbl = _control as  System.Web.UI.WebControls.RadioButtonList;
             _rbl.DataTextField = TextPropertyName;
             _rbl.DataValueField = ValuePropertyName;
             _rbl.DataSource = lst;
             _rbl.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
             //_rbl.RepeatLayout = RepeatLayout.Flow;
             _rbl.DataBind();
             if  (!isCheckedPropertyName)
                 _rbl.SelectedValue = CheckedPropertyName;
         }
 
     }
}
1
So it's convenient to call , Such as :
1
2
3
4
ExtControlHelper.BindCheckGroup( this , _db.SelectGeneralFromTableINFO(ShopID, CurrentFormID,
                                                                      "TerminationReason" ).ToList()
                                 , "cblTerminationReason" , "AttributeValue" , "AttributeID" , "CheckValue" ,
                                 4, " other " , 8);

But don't forget to drop one on the page “<ext:Hidden ID="cblTerminationReasonHidden" runat="server" />”.

For convenience , I also define the following functions :

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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/// <summary>
/// Bind radio box groups
/// </summary>
/// <typeparam name="T"> Class types </typeparam>
/// <param name="lst"> Generic set </param>
/// <param name="ID"> Check box group ID</param>
/// <param name="TextPropertyName"> The name of the text property field to be bound ( Capital letters and small letters must be the same )</param>
/// <param name="ValuePropertyName"> The name of the value property field that needs to be bound ( Capital letters and small letters must be the same )</param>
/// <param name="CheckedPropertyName"> The field name of the selection property to be bound ( Capital letters and small letters must be the same )</param>
/// <param name="isCheckedPropertyName"> Whether to select the property field name , If such as false, be CheckedPropertyName Represents the selected value </param>
/// <param name="_ColumnsNumber"> Show the number of columns </param>
public  static  void  BindRadioGroup<T>(System.Web.UI.UserControl _userControl, List<T> lst, string  ID, string  TextPropertyName, string  ValuePropertyName, string  CheckedPropertyName, bool  isCheckedPropertyName, int ? _ColumnsNumber)
{
     if  (lst != null  && lst.Count > 0)
     {
         Control _control = _userControl.FindControl(ID);
         if  (_control is  RadioGroup)
         {
             RadioGroup groupRadios = _control as  RadioGroup;
             if  (groupRadios == null )
                 return ;
             #region 【_ColumnsNumber】 Set the number of display columns , by null One line shows 4 Column .
             _ColumnsNumber = _ColumnsNumber ?? 4;
             if  (lst.Count <= _ColumnsNumber)
             {
                 groupRadios.ColumnsNumber = lst.Count;
             }
             else
             {
                 groupRadios.ColumnsNumber = _ColumnsNumber.Value;
             }
             #endregion
             groupRadios.Items.Clear();
             int  i = 0;
             foreach  ( var  item in  lst)
             {
                 T t = item;
                 Type type = t.GetType();
                 Radio rdo = new  Radio();
                 rdo.ID = string .Format( "{0}items{1}" , ID, i);
                 PropertyInfo TextProInfo = type.GetProperty(TextPropertyName);
                 if  (TextProInfo == null )
                     ExtensionMethods.ThrowNullException(type, TextPropertyName);
 
                 PropertyInfo ValueProInfo = type.GetProperty(ValuePropertyName);
                 if  (ValueProInfo == null )
                     ExtensionMethods.ThrowNullException(type, ValuePropertyName);
 
                 object  objText = TextProInfo.GetValue(t, null );
                 rdo.BoxLabel = objText == null  ? string .Empty : objText.ToString();
                 object  objValue = ValueProInfo.GetValue(t, null ).ToString();
                 rdo.Tag = objValue == null  ? string .Empty : objValue.ToString();
                 rdo.InputValue = objValue == null  ? string .Empty : objValue.ToString();
 
                 if  (!isCheckedPropertyName)
                 {
                     if  (rdo.Tag == CheckedPropertyName)
                         rdo.Checked = true ;
                     groupRadios.Items.Add(rdo);
                     i++;
                     continue ;
                 }
                 PropertyInfo CheckedProInfo = type.GetProperty(CheckedPropertyName);
                 if  (CheckedProInfo == null )
                     ExtensionMethods.ThrowNullException(type, CheckedPropertyName);
 
 
                 if  ((CheckedProInfo.GetValue(t, null ) ?? 0).ToString() == "1" )
                     rdo.Checked = true ;
                 groupRadios.Items.Add(rdo);
                 i++;
             }
         }
         else  if  (_control is  System.Web.UI.WebControls.RadioButtonList)
         {
             System.Web.UI.WebControls.RadioButtonList _rbl = _control as  System.Web.UI.WebControls.RadioButtonList;
             _rbl.DataTextField = TextPropertyName;
             _rbl.DataValueField = ValuePropertyName;
             _rbl.DataSource = lst;
             _rbl.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
             //_rbl.RepeatLayout = RepeatLayout.Flow;
             _rbl.DataBind();
             if  (!isCheckedPropertyName)
                 _rbl.SelectedValue = CheckedPropertyName;
         }
 
     }
}
/// <summary>
/// Bind check box group
/// </summary>
/// <typeparam name="T"> Class types </typeparam>
/// <param name="lst"> Generic set </param>
/// <param name="ID"> Check box group ID</param>
/// <param name="TextPropertyName"> The name of the text property field to be bound ( Capital letters and small letters must be the same )</param>
/// <param name="ValuePropertyName"> The name of the value property field that needs to be bound ( Capital letters and small letters must be the same )</param>
/// <param name="CheckedPropertyName"> The field name of the selection property to be bound ( Capital letters and small letters must be the same )</param>
public  static  void  BindCheckGroup<T>(Control _userControl, List<T> lst, string  ID, string  TextPropertyName, string  ValuePropertyName, string  CheckedPropertyName, int ? _ColumnsNumber)
{
     if  (lst != null  && lst.Count > 0)
     {
         Control _control = _userControl.FindControl(ID);
         if  (_control is  CheckboxGroup)
         {
             CheckboxGroup groupChks = _control as  CheckboxGroup;
             if  (groupChks == null )
                 return ;
             #region 【_ColumnsNumber】 Set the number of display columns , by null One line shows 4 Column .
             _ColumnsNumber = _ColumnsNumber ?? 4;
             if  (lst.Count <= _ColumnsNumber)
             {
                 groupChks.ColumnsNumber = lst.Count;
             }
             else
             {
                 groupChks.ColumnsNumber = _ColumnsNumber.Value;
             }
             #endregion
             groupChks.Items.Clear();
             int  i = 0;
             foreach  ( var  item in  lst)
             {
                 T t = item;
                 Type type = t.GetType();
                 Checkbox chk = new  Checkbox();
                 chk.ID = string .Format( "{0}items{1}" , ID, i);
                 PropertyInfo TextProInfo = type.GetProperty(TextPropertyName);
                 if  (TextProInfo == null )
                     ExtensionMethods.ThrowNullException(type, TextPropertyName);
                 PropertyInfo ValueProInfo = type.GetProperty(ValuePropertyName);
                 if  (ValueProInfo == null )
                     ExtensionMethods.ThrowNullException(type, ValuePropertyName);
                 PropertyInfo CheckedProInfo = type.GetProperty(CheckedPropertyName);
                 if  (CheckedProInfo == null )
                     ExtensionMethods.ThrowNullException(type, CheckedPropertyName);
                 object  objText = TextProInfo.GetValue(t, null );
                 chk.BoxLabel = objText == null  ? string .Empty : objText.ToString();
                 object  objValue = ValueProInfo.GetValue(t, null ).ToString();
                 chk.Tag = objValue == null  ? string .Empty : objValue.ToString();
                 chk.InputValue = chk.Tag;
                 //chk.InputValue = objValue == null ? string.Empty : objValue.ToString();
                 var  _checkValue = (CheckedProInfo.GetValue(t, null ) ?? 0).ToString();
                 if  (_checkValue == "1"  || (_checkValue != null  && _checkValue.ToLower() == "true" ))
                     chk.Checked = true ;
                 groupChks.Items.Add(chk);
                 i++;
             }
         }
         else  if  (_control is  System.Web.UI.WebControls.CheckBoxList)
         {
             System.Web.UI.WebControls.CheckBoxList _cbl = _control as  System.Web.UI.WebControls.CheckBoxList;
             _cbl.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
             _cbl.RepeatLayout = System.Web.UI.WebControls.RepeatLayout.Table;
             _cbl.RepeatColumns = 7;
             _cbl.Width = System.Web.UI.WebControls.Unit.Parse( "100%" );
             foreach  ( var  item in  lst)
             {
                 T t = item;
                 Type type = t.GetType();
                 Checkbox chk = new  Checkbox();
                 PropertyInfo TextProInfo = type.GetProperty(TextPropertyName);
                 if  (TextProInfo == null )
                     ExtensionMethods.ThrowNullException(type, TextPropertyName);
                 PropertyInfo ValueProInfo = type.GetProperty(ValuePropertyName);
                 if  (ValueProInfo == null )
                     ExtensionMethods.ThrowNullException(type, ValuePropertyName);
                 PropertyInfo CheckedProInfo = type.GetProperty(CheckedPropertyName);
                 if  (CheckedProInfo == null )
                     ExtensionMethods.ThrowNullException(type, CheckedPropertyName);
 
                 object  objText = TextProInfo.GetValue(t, null );
                 object  objValue = ValueProInfo.GetValue(t, null ).ToString();
 
                 System.Web.UI.WebControls.ListItem _li = new  System.Web.UI.WebControls.ListItem();
                 _li.Text = objText == null  ? string .Empty : objText.ToString();
                 _li.Value = objValue == null  ? string .Empty : objValue.ToString();
                 var  _checkValue = CheckedProInfo.GetValue(t, null ).ToString();
                 if  (_checkValue == "1"  || (_checkValue != null  && _checkValue.ToLower() == "true" ))
                     _li.Selected = true ;
                 _cbl.Items.Add(_li);
             }
         }
 
     }
}
 
/// <summary>
/// Bind check box group ( The last item is an editable item , Keep the position at ID+Hidden)
/// </summary>
/// <typeparam name="T"> Class types </typeparam>
/// <param name="lst"> Generic set </param>
/// <param name="ID"> Check box group ID</param>
/// <param name="TextPropertyName"> The name of the text property field to be bound ( Capital letters and small letters must be the same )</param>
/// <param name="ValuePropertyName"> The name of the value property field that needs to be bound ( Capital letters and small letters must be the same )</param>
/// <param name="CheckedPropertyName"> The field name of the selection property to be bound ( Capital letters and small letters must be the same )</param>
/// <param name="_ColumnsNumber"> Show the number of columns </param>
/// <param name="_remark"> Note item name , If this item is set , You can fill in the remark </param>
/// <param name="textlen"> The length of the text displayed </param>
public  static  void  BindCheckGroup<T>(Control _userControl, List<T> lst, string  ID, string  TextPropertyName, string  ValuePropertyName, string  CheckedPropertyName, int ? _ColumnsNumber, string  _remark, int  textlen)
{
     if  (lst != null  && lst.Count > 0)
     {
         Control _control = _userControl.FindControl(ID);
         if  (_control is  CheckboxGroup)
         {
             ToolTip _tool= new  ToolTip();
             _tool.ID = string .Format( "{0}ToolTip" , ID);
             // The script realizes the pop-up box to fill in other items , Here are the parameters
             //hiddenID: Where the text of other items is saved ID
             //chk: Other items of CheckBox
             //orgBoxLabel: The original BoxLabel
             string  _setRemarkScript =
             @"
                         function setChkRemark(hiddenID, chk, orgBoxLabel ,textlen) {
                             if (chk.getValue()) {
                                 Ext.MessageBox.show({
                                     title: orgBoxLabel,
                                     msg: ' Please enter ' + orgBoxLabel + ':',
                                     width: 300,
                                     buttons: Ext.MessageBox.OKCANCEL,
                                     multiline: true,
                                     value: hiddenID.getValue(),
                                     fn: function (btn, text) {
                                         var remark = text.replace(/(^\s*)|(\s*$)/g, '');
                                         if (btn == 'cancel')
                                             Ext.MessageBox.alert(' reminder ', ' Operation cancelled .');
                                         else if (btn == 'ok') {
                                             hiddenID.setValue(remark);
                                             if (remark!='')
                                                 chk.setBoxLabel(orgBoxLabel+':'+(remark.length>textlen? remark.toString().substring(0,textlen)+'...':remark));
                                             else
                                                 chk.setBoxLabel(orgBoxLabel);
                                         }
                                     }
                                 });
                             }
                         }
             " ;
             // Register function
             _userControl.Page.ClientScript.RegisterStartupScript(_userControl.GetType(), "setChkRemark" , _setRemarkScript, true );
             CheckboxGroup groupChks = _control as  CheckboxGroup;
             if  (groupChks == null )
                 return ;
             #region 【_ColumnsNumber】 Set the number of display columns , by null One line shows 4 Column .
             _ColumnsNumber = _ColumnsNumber ?? 4;
             if  (lst.Count <= _ColumnsNumber)
             {
                 groupChks.ColumnsNumber = lst.Count;
             }
             else
             {
                 groupChks.ColumnsNumber = _ColumnsNumber.Value;
             }
             #endregion
             groupChks.Items.Clear();
             int  i = 0;
             foreach  ( var  item in  lst)
             {
                 T t = item;
                 Type type = t.GetType();
                 Checkbox chk = new  Checkbox();
                 chk.ID = string .Format( "{0}items{1}" , ID, i);
                 PropertyInfo TextProInfo = type.GetProperty(TextPropertyName);
                 if  (TextProInfo == null )
                     ExtensionMethods.ThrowNullException(type, TextPropertyName);
 
                 PropertyInfo ValueProInfo = type.GetProperty(ValuePropertyName);
                 if  (ValueProInfo == null )
                     ExtensionMethods.ThrowNullException(type, ValuePropertyName);
 
                 PropertyInfo CheckedProInfo = type.GetProperty(CheckedPropertyName);
                 if  (CheckedProInfo == null )
                     ExtensionMethods.ThrowNullException(type, CheckedPropertyName);
 
                 object  objText = TextProInfo.GetValue(t, null );
 
                 chk.BoxLabel = objText == null  ? string .Empty : objText.ToString();
                 chk.ToolTip = objText == null  ? string .Empty : objText.ToString();
                 object  objValue = ValueProInfo.GetValue(t, null ).ToString();
                 chk.Tag = objValue == null  ? string .Empty : objValue.ToString();
                 chk.InputValue = chk.Tag;
 
                 //chk.InputValue = objValue == null ? string.Empty : objValue.ToString();
                 var  _checkValue = (CheckedProInfo.GetValue(t, null ) ?? 0).ToString();
 
                 if  (_checkValue == "1"  || (_checkValue != null  && _checkValue.ToLower() == "true" ))
                     chk.Checked = true ;
                 //if (i == lst.Count - 1)
                 //{
                 //    chk.Listeners.Check.Handler = "setChkRemark(#{" + ID + "Hidden},this,'" + _remark + "'," + textlen + ");";
                 //    //chk.Icons.Add(Icon.Note);
                 //}
                 groupChks.Items.Add(chk);
                 i++;
             }
             groupChks.Items[groupChks.Items.Count - 1].Listeners.Check.Handler = string .Format( "setChkRemark(#{{{0}Hidden}},this,'{1}',{2});" , ID, _remark, textlen);
             //groupChks.Items[groupChks.Items.Count - 1].ToolTip=
         }
         else  if  (_control is  System.Web.UI.WebControls.CheckBoxList)
         {
             System.Web.UI.WebControls.CheckBoxList _cbl = _control as  System.Web.UI.WebControls.CheckBoxList;
             _cbl.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
             _cbl.RepeatLayout = System.Web.UI.WebControls.RepeatLayout.Table;
             _cbl.RepeatColumns = 7;
             _cbl.Width = System.Web.UI.WebControls.Unit.Parse( "100%" );
             foreach  ( var  item in  lst)
             {
                 T t = item;
                 Type type = t.GetType();
                 Checkbox chk = new  Checkbox();
                 PropertyInfo TextProInfo = type.GetProperty(TextPropertyName);
                 if  (TextProInfo == null )
                     ExtensionMethods.ThrowNullException(type, TextPropertyName);
                 PropertyInfo ValueProInfo = type.GetProperty(ValuePropertyName);
                 if  (ValueProInfo == null )
                     ExtensionMethods.ThrowNullException(type, ValuePropertyName);
                 PropertyInfo CheckedProInfo = type.GetProperty(CheckedPropertyName);
                 if  (CheckedProInfo == null )
                     ExtensionMethods.ThrowNullException(type, CheckedPropertyName);
 
                 object  objText = TextProInfo.GetValue(t, null );
                 object  objValue = ValueProInfo.GetValue(t, null ).ToString();
 
                 System.Web.UI.WebControls.ListItem _li = new  System.Web.UI.WebControls.ListItem();
                 _li.Text = objText == null  ? string .Empty : objText.ToString();
                 _li.Value = objValue == null  ? string .Empty : objValue.ToString();
                 var  _checkValue = CheckedProInfo.GetValue(t, null ).ToString();
                 if  (_checkValue == "1"  || (_checkValue != null  && _checkValue.ToLower() == "true" ))
                     _li.Selected = true ;
                 _cbl.Items.Add(_li);
             }
         }
 
     }
}

2) The drop-down list .

No plan, no truth , The picture above is decisive .

Bind drop-down list , ad locum , I also encapsulate the following . Like the following code :

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
/// <summary>
/// Bind the drop-down list by reflection
/// </summary>
/// <typeparam name="T"> Class types </typeparam>
/// <param name="lst"> Generic set </param>
/// <param name="ID"> The drop-down list ID</param>
/// <param name="TextPropertyName"> Text property name </param>
/// <param name="ValuePropertyName"> Value property name </param>
/// <param name="_SelectValue"> Selected value </param>
public  static  void  BindComobox<T>(Control _userControl, List<T> lst, string  ID, string  TextPropertyName, string  ValuePropertyName, string  _SelectValue)
{
     if  (lst != null  && lst.Count > 0)
     {
         ComboBox _cbos = _userControl.FindControl(ID) as  ComboBox;
         if  (_cbos == null )
             return ;
         _cbos.Items.Clear();
         foreach  ( var  item in  lst)
         {
             T t = item;
             Type type = t.GetType();
             ListItem _li = new  ListItem();
             // Text attribute
             PropertyInfo TextProInfo = type.GetProperty(TextPropertyName);
             if  (TextProInfo == null )
                 ExtensionMethods.ThrowNullException(type, TextPropertyName);
             // Value attribute
             PropertyInfo ValueProInfo = type.GetProperty(ValuePropertyName);
             if  (ValueProInfo == null )
                 ExtensionMethods.ThrowNullException(type, ValuePropertyName);
 
             object  objText = TextProInfo.GetValue(t, null );
             _li.Text = objText == null  ? string .Empty : objText.ToString();
             object  objValue = ValueProInfo.GetValue(t, null ).ToString();
             _li.Value = objValue == null  ? string .Empty : objValue.ToString();
             _cbos.Items.Add(_li);
         }
         if  (! string .IsNullOrEmpty(_SelectValue))
             _cbos.SelectedItem.Value = _SelectValue;
     }
}

In fact, there is another way to bind , But I prefer this . Such as through Store:

1
2
3
4
5
_store = new  Store { ID = string .Format( "_store{0}" , Guid.NewGuid().ToString( "N" )), IDMode = IDMode.Static };
                    _jsonReader = new  JsonReader();
                    _jsonReader.Fields.Add( new  RecordField( "text" , RecordFieldType.String));
                    _jsonReader.Fields.Add( new  RecordField( "value" , RecordFieldType.String));
                    _store.Reader.Add(_jsonReader);

And then add your own definition of URL And parameters , Define a few parameters , Encapsulate the , It can also be universal , I won't go on writing here .

3)SharePoint in , to EXT.NET Empowerment .

This code , Give it to those who need it . At the beginning, this problem made me crazy . Fortunately, I came up with such a solution .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/// <summary>
/// to EXT.NET Scripts give privileges
/// </summary>
/// <param name="ResManager">ResourceManager</param>
public  static  void  BuildAllPrivilegesForExtNET( this  ResourceManager ResManager)
{
     if  (!X.IsAjaxRequest)
     {
         SPSecurity.RunWithElevatedPrivileges(
             delegate ()
             {
                 ResManager.RenderScripts = ResourceLocationType.Embedded;
                 ResManager.BuildScripts();
                 ResManager.RenderStyles = ResourceLocationType.Embedded;
                 ResManager.BuildStyles();
             }
         );
     }
}

4) Read and assign .

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
/// <summary>
/// Set the property value of the type
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="t"></param>
/// <param name="userControl"> User control </param>
public  static  void  SetValues<T>( this  System.Web.UI.Control userControl, T t)
{
     Type type = t.GetType();
     if  (type.IsClass)
     {
         var  properties = type.GetProperties();
         foreach  ( var  item in  properties)
         {
             if  (item.CanWrite)
             {
                 System.Web.UI.Control control = userControl.FindControl( "txt"  + item.Name);
                 if  (control != null )
                 {
                     string  text = string .Empty;
                     if  (control is  DateField)
                     {
                         DateField _df = control as  DateField;
 
                         if  (_df.IsEmpty)
                         {
                             if  (item.PropertyType.IsGenericType && item.PropertyType.GetGenericTypeDefinition() == typeof (Nullable<>))
                                 item.SetValue(t, null , null );
                             //else
                             //    item.SetValue(t, System.Data.DbType.DateTime., null);
                             continue ;
                         }
                         else
                             text = _df.Text;
                     }
                     if  (control is  TextFieldBase)
                         text = (control as  TextFieldBase).Text.Trim();
 
                     if  (item.PropertyType.IsEnum)
                     {
                         item.SetValue(t, Enum.ToObject(item.PropertyType, text), null );
                     }
                     else
                     {
                         // Determine whether it is a nullable type
                         if  (item.PropertyType.IsGenericType && item.PropertyType.GetGenericTypeDefinition() == typeof (Nullable<>))
                         {
                             if  (item.PropertyType.GetGenericArguments()[0].Equals( typeof (DateTime)) && text == "0001/1/1 0:00:00" )
                                 item.SetValue(t, null , null );
                             else
                                 item.SetValue(t, Convert.ChangeType(text, item.PropertyType.GetGenericArguments()[0]), null );
                         }
                         else
                             item.SetValue(t, Convert.ChangeType(text, item.PropertyType), null );
                     }
                 }
             }
         }
     }
}
 
/// <summary>
/// Set the property value of the control
/// </summary>
/// <typeparam name="T"> type </typeparam>
/// <param name="t"> Class object </param>
/// <param name="userControl"> User control </param>
public  static  void  SetControlValues<T>( this  System.Web.UI.UserControl userControl, T t)
{
     Type type = t.GetType();
     if  (type.IsClass)
     {
         var  properties = type.GetProperties();
         foreach  ( var  item in  properties)
         {
             System.Web.UI.Control control = userControl.FindControl( "txt"  + item.Name);
             if  (control != null )
             {
                 if  (control is  TextFieldBase)
                 {
                     TextFieldBase txt = control as  TextFieldBase;
                     object  obj = item.GetValue(t, null );
                     if  (obj != null )
                         txt.Text = obj.ToString();
                 }
                 else  if  (control is  DisplayField)
                 {
                     DisplayField txt = control as  DisplayField;
                     object  obj = item.GetValue(t, null );
                     if  (obj != null )
                         txt.Text = obj.ToString();
                 }
             }
         }
     }
}
 The above code makes the judgment of nullable type , This is something to be aware of .
5) Set up a common form validation script .
1
It's time to draw a picture .

1
First of all, the form page that needs to be verified must be hung with this paragraph JS:
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
var  valCss = '' ;
 
function  showMsg(title, content, cs) {
 
     if  (valCss != cs) {
 
         valCss = cs;
 
         Ext.net.Notification.show({
 
             hideFx: {
 
                 fxName: 'switchOff' ,
 
                 args: [{}]
 
             },
 
             showFx: {
 
                 args: [
 
                           'C3DAF9' ,
 
                           1,
 
                           {
 
                               duration: 2.0
 
                           }
 
                       ],
 
                 fxName: 'frame'
 
             },
 
             iconCls: cs,
 
             closeVisible: true ,
 
             html: content,
 
             title: title + '   '  + new  Date().format( 'g:i:s A' )
 
         });
 
     }
 
}

then :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
if  (! string .IsNullOrEmpty(_fp.Listeners.ClientValidation.Handler))
     return ;
_fp.Listeners.ClientValidation.Handler =
     @"
                 var isCheckd=valid;var msgs;var msg='';
                 if(typeof(ValCustomValidator)=='function')
                 {
                     msgs=ValCustomValidator(false,valid);
                     if(typeof(msgs.IsVal)!='undefined')
                     {
                         isCheckd=msgs.IsVal;
                         if(msgs.Message!='')
                         msg='<span style=\'color:red;\'>'+msgs.Message+'</span>';
                     }
                     else
                         isCheckd=msgs;
                 }
                 if(typeof(#{btnSave})!='undefined' && #{btnSave}!=null)#{btnSave}.setDisabled(!isCheckd);
                 if(typeof(#{btnSumbit1})!='undefined' && #{btnSumbit1}!=null)#{btnSumbit1}.setDisabled(!isCheckd);
              var valCs=isCheckd ? 'valaccept' : 'valexclamation';
              if (msg=='') msg=isCheckd ? '<span style=\'color:green;\'> Verification passed , You can submit data </span>' : '<span style=\'color:red;\'> Incorrect input , Please check the input marked in red .</span>';
              this.getBottomToolbar().setStatus({text :msg, iconCls: valCs});showMsg(' reminder ',msg,valCs);
   " ;

By the way, explain :

  1. Support to write custom verification function on the page “ValCustomValidator”. No exception is thrown if it exists or not .
  2. Prevent save submit button on support page , It doesn't matter whether it exists or not .
  3. You can also customize it according to your own situation .

Because it's universal , For example, this validation script is used by default for each form . So how to implement custom validation ? Enjoy two beautiful pictures first :

And then there's a hint in the lower right corner :

I'll post it here JS:

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
     var  ids1 = [
"ctl00_ctl07_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_ASP_wpresources_usercontrols_form_packagenotice_ascx_txt100E44D593C054BFD9B13EBFBD9AAA41A" , "ctl00_ctl07_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_ASP_wpresources_usercontrols_form_packagenotice_ascx_txt124C85DB03BA04EBDBE5055EAC5FACAEC" , "ctl00_ctl07_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_ASP_wpresources_usercontrols_form_packagenotice_ascx_txt1DF8DD73F58F84492B89D7194D52D947F" , "ctl00_ctl07_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_ASP_wpresources_usercontrols_form_packagenotice_ascx_txt1ADD45D7F275148769BD0E20013DC25F2" ];
 
     var  ids2 = [ "ctl00_ctl07_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_ASP_wpresources_usercontrols_form_packagenotice_ascx_txt200E44D593C054BFD9B13EBFBD9AAA41A" , "ctl00_ctl07_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_ASP_wpresources_usercontrols_form_packagenotice_ascx_txt224C85DB03BA04EBDBE5055EAC5FACAEC" , "ctl00_ctl07_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_ASP_wpresources_usercontrols_form_packagenotice_ascx_txt2DF8DD73F58F84492B89D7194D52D947F" , "ctl00_ctl07_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_g_6fdea0d3_1768_457b_a4ba_ff8b3fc1ea4e_ASP_wpresources_usercontrols_form_packagenotice_ascx_txt2ADD45D7F275148769BD0E20013DC25F2" ];
     function valSumMax(ids, maxValue, msg) {
         if  (ids != null  && ids.length > 0) {
             var  _temp = 0;
             for  ( var  i = 0; i < ids.length; i++) {
                 var  value = Ext.getCmp(ids[i]).getValue();
                 var  _currentValue = parseInt(value);
                 _temp += isNaN(_currentValue) ? 0 : _currentValue;
                 if  (_temp > maxValue) {
 
                     var  message = { 'IsVal' : false , 'Message' : msg != ""  ? msg : ( " Current value "  + _temp + " Over the maximum "  + maxValue + "." ) };
                     return  message;
                 }
             }
         }
         var  message = { 'IsVal' : true , 'Message' : ''  };
         return  message;
     }
     function CustomValidator() {
         var  msg = valSumMax(ids1, 2, " Beauty consultant clothing can only fill in 2 Pieces of . Please change the total ." );
         if  (!msg.IsVal)
             return  msg;
         msg = valSumMax(ids2, 6, " Beautician clothing can only fill in 6 Pieces of . Please change the total ." );
         return  msg;
     }
     function ValCustomValidator(isVal, valid) {
         if  ( typeof  (valid) != 'undefined'  && (!valid))
             return  valid;
         if  ( typeof  (isVal) == 'undefined'  || isVal == null  || isVal) {
             var  msg = CustomValidator();
             if  (!msg.IsVal) {
                 Ext.MessageBox.show({
                     title: ' error ' ,
                     msg: msg.Message,
                     buttons: Ext.MessageBox.OK,
                     icon: Ext.MessageBox.ERROR
                 });
                 return  false ;
             } else  {
                 return  true ;
             }
         } else  {
             return  CustomValidator();
         }
     }

See the string above ID no , That's not using IDMode The consequences of . Because it's just beginning to touch , I didn't find such a good thing .

EXT.NET Efficient development ( Two )—— More articles on encapsulating functions

  1. EXT.NET Efficient development ( 3、 ... and )—— Use Chrome Browser developer tools

    This post is suitable for all ages , Regardless of gender , Regardless of race , Regardless of occupation . It is said that :“ Sharpening a knife never misses a woodcutter ”. Master the use of some development tools , It's great to help yourself ( Whether it's used to analyze problems , Or increase productivity ). This article is about how to use Chrome browser ( here ...

  2. ios Efficient development II --ARC Follow block That thing

    block Is a special block of code that captures context . block Access is defined in block External variables , When in block When used in , It creates a copy for each scalar variable it has in scope . If you pass self To have a block, then ...

  3. js Object oriented learning notes ( Two ): The factory way : Packaging function

    // The factory way : Packaging function function test(name) { var obj = new Object(); obj.name = name; obj.sayName = function () ...

  4. 《Python Efficient development practice 》 Practical drill —— Basic view 3

    At the completion of Django After the establishment of projects and Applications , You can start writing website application code , Here, by displaying a welcome title for the registration page , To demonstrate Django The routing mapping function of . 1) First, in the djangosite/app/views.py To establish ...

  5. Python Server development II :Python Network foundation

    Python Server development II :Python Network foundation   The network is divided into physical layer from bottom to top . Data link layer . The network layer . Transport layer . The session layer . Presentation layer and application layer . HTTP It's a high-level agreement , and TCP/IP It's a protocol set , Lots of sub protocols . Include : ...

  6. Oracle Call in database Java Class development stored procedure 、 Function method

    Oracle Call in database Java Class development stored procedure . Function method Time :2014 year 12 month 24 Japan    Browse :5538 Time oracle Database development is very flexible , Not only support the most basic SQL, And it also provides unique PL/SQL, ...

  7. javaweb learning Servlet Development ( Two )

    javaweb Learning summary ( 6、 ... and )--Servlet Development ( Two ) One .ServletConfig Explain 1.1. To configure Servlet Initialize parameters stay Servlet Configuration file for web.xml in , You can use one or more < ...

  8. Android APP Ten suggestions for efficient development

    In the use of Android Development APP In the process , Why ensure optimization . Run smoothly and don't make Android It's very important that there is a problem in the system ? Because of the impact APP Every issue of product efficiency , Such as : Power consumption or memory usage, etc , It's all about APP The key to success is ...

  9. Android Development -- Two dimensional code development and application ( Reprint !)

    android Project development QR code scanning   be based on android Two dimensional code scanning project of the platform , You can view the results and link to the website Tools / raw material zxing eclipse Method / step   First of all, we need to use google Provided zxin ...

Random recommendation

  1. people have been arrested under other offences instead.

    Homosexuality is not explicitly banned in Egypt but gay people have been arrested under other offenc ...

  2. javascript identifier

    identifier , It means variable . function . Property name , Or the parameters of the function . The rules 1. The first character must be a letter . It's a dollar or an underline ($) 2. Other characters can be letters . Underline . Dollar sign or number 3. Can't be keywords and reserved words 4. distinguish ...

  3. Aspect Oriented Programming

    AOP(Aspect Oriented Programming), Section oriented programming ( It's also called aspect oriented ) It is a hot spot in software development . utilize AOP Parts of the business logic can be isolated , So that the coupling degree between the parts of business logic ...

  4. C Language -- Pointer problem _1

    #include <stdio.h> #include <string.h> main() { int *a,*b,*c; a=b=c=(int *)malloc(sizeof ...

  5. struts2 Access and add Application、session as well as request attribute

    One . Visit or add Application.session.request attribute < One > Mode one HelloWorldAction Class to add the following code // This method is applicable only to Application.ses ...

  6. Eclipse In the environment JBoss debugging , Solve the problem that the referenced project is not deployed

    Actually, it's a very small experience , stay eclipse In an environment jboss Deployment of , Because the problem of defining a public package , Put the code down I came down to do a project , Deployment found jboss Tips :class not found! from jboss Deploy ...

  7. Jlink Write a picture and text course

    , Click on the install           , Plug in jlink, After installing the driver , The red light is always on                                                                 ...

  8. linux Backup log files

    seo It's about backing up files , And then I can't make it myself , One document a day . Wrote a shell, Add a crontab -e Mission . Once a day . crontab: 59 23 * * * /root/sh/dumpApacheLo ...

  9. overflow Attribute and its application in ios Next, the Caton problem is solved

    overflow attribute :http://www.w3school.com.cn/cssref/pr_pos_overflow.asp overflow:scroll/auto; Gliding on the mobile page is not smooth : ...

  10. Red Hat 9.0 Linux Resolution modification

    Red Hat 9.0 Linux Resolution modification I was in VMware Workstation There's a red hat in it Linux System , I found that the resolution was a little low after I installed it , yes 800x600 Of , It's uncomfortable to watch , And then I thought about what to do, but ...