-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathDisplayFormatAttribute.xml
530 lines (484 loc) · 37.4 KB
/
DisplayFormatAttribute.xml
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
<Type Name="DisplayFormatAttribute" FullName="System.ComponentModel.DataAnnotations.DisplayFormatAttribute">
<TypeSignature Language="C#" Value="public class DisplayFormatAttribute : Attribute" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit DisplayFormatAttribute extends System.Attribute" />
<TypeSignature Language="DocId" Value="T:System.ComponentModel.DataAnnotations.DisplayFormatAttribute" />
<TypeSignature Language="VB.NET" Value="Public Class DisplayFormatAttribute
Inherits Attribute" />
<TypeSignature Language="F#" Value="type DisplayFormatAttribute = class
 inherit Attribute" />
<TypeSignature Language="C++ CLI" Value="public ref class DisplayFormatAttribute : Attribute" />
<AssemblyInfo>
<AssemblyName>System.ComponentModel.Annotations</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.3.0.0</AssemblyVersion>
<AssemblyVersion>4.3.1.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.DataAnnotations</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<TypeForwardingChain>
<TypeForwarding From="System.ComponentModel.DataAnnotations" FromVersion="4.0.0.0" To="System.ComponentModel.Annotations" ToVersion="0.0.0.0" FrameworkAlternate="dotnet-uwp-10.0;netcore-2.0" />
</TypeForwardingChain>
<Base>
<BaseTypeName>System.Attribute</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute>
<AttributeName Language="C#">[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)]</AttributeName>
<AttributeName Language="F#">[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-10.0;net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Specifies how data fields are displayed and formatted by ASP.NET Dynamic Data.</summary>
<remarks>
<format type="text/markdown"><).
## Examples
See an online example of this feature: [Run](https://go.microsoft.com/fwlink/?LinkId=120736&sref=System.ComponentModel.DataAnnotations.DisplayFormatAttribute).
The following example shows how to use the <xref:System.ComponentModel.DataAnnotations.DisplayFormatAttribute> to customize formatting for a data field. The example performs the following steps:
- Implements a metadata partial class and an associated metadata class.
- In the associated metadata class, it applies the <xref:System.ComponentModel.DataAnnotations.DisplayFormatAttribute> attribute to specify the following results:
- Display the text "[Null]" when a data field is empty.
- Display currency data in locale specific currency format.
- Display date information in short format (mm/dd/yy). This format also applies in edit mode.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.DisplayFormatAttribute/CS/product.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.DisplayFormatAttribute/VB/product.vb" id="Snippet1":::
To compile the example, you need the following:
- Any edition of Visual Studio 2010 or later.
- The AdventureWorksLT sample database. For information about how to download and install the SQL Server sample database, see [Microsoft SQL Server Product Samples: Database](https://github.com/Microsoft/sql-server-samples/releases) on GitHub. Make sure that you install the correct version of the sample database for the version of SQL Server that you are running.
- A data-driven Web site. This enables you to create a data context for the database and the class that contains the data field to customize. For more information, see `Walkthrough: Creating a New Dynamic Data Web Site using Scaffolding`.
]]></format>
</remarks>
<related type="Article" href="https://learn.microsoft.com/previous-versions/aspnet/bz9tc508(v=vs.100)">How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization</related>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public DisplayFormatAttribute ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.#ctor" />
<MemberSignature Language="VB.NET" Value="Public Sub New ()" />
<MemberSignature Language="C++ CLI" Value="public:
 DisplayFormatAttribute();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.Annotations</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.3.0.0</AssemblyVersion>
<AssemblyVersion>4.3.1.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.DataAnnotations</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters />
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.ComponentModel.DataAnnotations.DisplayFormatAttribute" /> class.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="ApplyFormatInEditMode">
<MemberSignature Language="C#" Value="public bool ApplyFormatInEditMode { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance bool ApplyFormatInEditMode" />
<MemberSignature Language="DocId" Value="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.ApplyFormatInEditMode" />
<MemberSignature Language="VB.NET" Value="Public Property ApplyFormatInEditMode As Boolean" />
<MemberSignature Language="F#" Value="member this.ApplyFormatInEditMode : bool with get, set" Usage="System.ComponentModel.DataAnnotations.DisplayFormatAttribute.ApplyFormatInEditMode" />
<MemberSignature Language="C++ CLI" Value="public:
 property bool ApplyFormatInEditMode { bool get(); void set(bool value); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.Annotations</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.3.0.0</AssemblyVersion>
<AssemblyVersion>4.3.1.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.DataAnnotations</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets a value that indicates whether the formatting string that is specified by the <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.DataFormatString" /> property is applied to the field value when the data field is in edit mode.</summary>
<value>
<see langword="true" /> if the formatting string applies to the field value in edit mode; otherwise, <see langword="false" />. The default is <see langword="false" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
By default, the formatting string that is specified by the <xref:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.DataFormatString%2A> property is applied to field values only when the data-bound control is in read-only mode.
## Examples
The following example shows how to use the <xref:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.ApplyFormatInEditMode%2A> property to set the display format for date information when the data field is in edit mode. The data field format to use for the data field is specified by setting the <xref:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.DataFormatString%2A> property.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.DisplayFormatAttribute/CS/product.cs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.DisplayFormatAttribute/VB/product.vb" id="Snippet4":::
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="ConvertEmptyStringToNull">
<MemberSignature Language="C#" Value="public bool ConvertEmptyStringToNull { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance bool ConvertEmptyStringToNull" />
<MemberSignature Language="DocId" Value="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.ConvertEmptyStringToNull" />
<MemberSignature Language="VB.NET" Value="Public Property ConvertEmptyStringToNull As Boolean" />
<MemberSignature Language="F#" Value="member this.ConvertEmptyStringToNull : bool with get, set" Usage="System.ComponentModel.DataAnnotations.DisplayFormatAttribute.ConvertEmptyStringToNull" />
<MemberSignature Language="C++ CLI" Value="public:
 property bool ConvertEmptyStringToNull { bool get(); void set(bool value); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.Annotations</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.3.0.0</AssemblyVersion>
<AssemblyVersion>4.3.1.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.DataAnnotations</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets a value that indicates whether empty string values ("") are automatically converted to <see langword="null" /> when the data field is updated in the data source.</summary>
<value>
<see langword="true" /> if empty string values are automatically converted to <see langword="null" />; otherwise, <see langword="false" />. The default is <see langword="true" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Users might enter an empty string for a field value. Use the <xref:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.ConvertEmptyStringToNull%2A> property to specify whether an empty string value is automatically converted to `null` when the data field is updated in the database.
> [!NOTE]
> By default, a <xref:System.Web.DynamicData.DynamicField> object displays `null` values as empty strings. To display a different value, set the <xref:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayText%2A> property.
## Examples
The following example shows how to use the <xref:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.ConvertEmptyStringToNull%2A> to enable the conversion of empty string values to `null`.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.DisplayFormatAttribute/CS/product.cs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.DisplayFormatAttribute/VB/product.vb" id="Snippet2":::
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="DataFormatString">
<MemberSignature Language="C#" Value="public string DataFormatString { get; set; }" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0-pp" />
<MemberSignature Language="ILAsm" Value=".property instance string DataFormatString" />
<MemberSignature Language="DocId" Value="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.DataFormatString" />
<MemberSignature Language="VB.NET" Value="Public Property DataFormatString As String" />
<MemberSignature Language="F#" Value="member this.DataFormatString : string with get, set" Usage="System.ComponentModel.DataAnnotations.DisplayFormatAttribute.DataFormatString" />
<MemberSignature Language="C++ CLI" Value="public:
 property System::String ^ DataFormatString { System::String ^ get(); void set(System::String ^ value); };" />
<MemberSignature Language="C#" Value="public string? DataFormatString { get; set; }" FrameworkAlternate="net-10.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netstandard-2.1-pp" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.Annotations</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.3.0.0</AssemblyVersion>
<AssemblyVersion>4.3.1.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.DataAnnotations</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the display format for the field value.</summary>
<value>A formatting string that specifies the display format for the value of the data field. The default is an empty string (""), which indicates that no special formatting is applied to the field value.</value>
<remarks>
<format type="text/markdown"><.
> [!NOTE]
> When the <xref:System.Web.DynamicData.DynamicField.HtmlEncode%2A?displayProperty=nameWithType> property is `true`, the value of the field is HTML encoded to its string representation before the formatting string is applied. For some objects, such as dates, you might want to control how the object is displayed with a formatting string. In those cases, you must set the <xref:System.Web.DynamicData.DynamicField.HtmlEncode%2A?displayProperty=nameWithType> property to `false`.
By default, the formatting string is applied to the field value only when the data-bound control that contains the <xref:System.Web.DynamicData.DynamicField> object is in read-only mode. To apply the formatting string to field values when they are in edit mode, set the <xref:System.Web.DynamicData.DynamicField.ApplyFormatInEditMode%2A> property to `true`.
The formatting string can be any literal string and usually includes a placeholder for the field's value. For example, in the formatting string "Item Value: {0}", the field's value is substituted for the {0} placeholder when the string is displayed in the <xref:System.Web.DynamicData.DynamicField> object. The remainder of the formatting string is displayed as literal text.
> [!NOTE]
> If the formatting string does not include a placeholder, the field's value from the data source is not included in the final display text.
## Examples
The following examples show how to use the <xref:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.DataFormatString%2A> property to set the display format of data fields. The first example sets the display format for a currency type data field. The second example sets the display format for a date type data field.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.DisplayFormatAttribute/CS/product.cs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.DisplayFormatAttribute/VB/product.vb" id="Snippet3":::
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.DisplayFormatAttribute/CS/product.cs" id="Snippet4":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.DisplayFormatAttribute/VB/product.vb" id="Snippet4":::
]]></format>
</remarks>
<related type="Article" href="/dotnet/standard/base-types/formatting-types">Formatting Types in .NET</related>
</Docs>
</Member>
<Member MemberName="GetNullDisplayText">
<MemberSignature Language="C#" Value="public string? GetNullDisplayText ();" FrameworkAlternate="net-10.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netstandard-2.1-pp" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance string GetNullDisplayText() cil managed" />
<MemberSignature Language="DocId" Value="M:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.GetNullDisplayText" />
<MemberSignature Language="VB.NET" Value="Public Function GetNullDisplayText () As String" />
<MemberSignature Language="F#" Value="member this.GetNullDisplayText : unit -> string" Usage="displayFormatAttribute.GetNullDisplayText " />
<MemberSignature Language="C++ CLI" Value="public:
 System::String ^ GetNullDisplayText();" />
<MemberSignature Language="C#" Value="public string GetNullDisplayText ();" FrameworkAlternate="netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netstandard-2.0-pp" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.Annotations</AssemblyName>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.3.0.0</AssemblyVersion>
<AssemblyVersion>4.3.1.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.DataAnnotations</AssemblyName>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns the UI display string for <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayText" />. </summary>
<returns>
<para>The UI display string.</para>
<para>If <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayTextResourceType" /> has not been specified, the value of <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayText" /> is returned.</para>
<para>If <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayTextResourceType" /> has been specified and <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayText" /> represents a resource key within that resource type, the localized value is returned.</para>
<para>If <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayText" /> and <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayTextResourceType" /> have not been set, returns <see langword="null" />.</para>
</returns>
<remarks>To be added.</remarks>
<exception cref="T:System.InvalidOperationException">Both the <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayTextResourceType" /> and <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayText" /> properties are set, but a public static property with a name matching the <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayText" /> value cannot be found on the <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayTextResourceType" />.
</exception>
</Docs>
</Member>
<Member MemberName="HtmlEncode">
<MemberSignature Language="C#" Value="public bool HtmlEncode { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance bool HtmlEncode" />
<MemberSignature Language="DocId" Value="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.HtmlEncode" />
<MemberSignature Language="VB.NET" Value="Public Property HtmlEncode As Boolean" />
<MemberSignature Language="F#" Value="member this.HtmlEncode : bool with get, set" Usage="System.ComponentModel.DataAnnotations.DisplayFormatAttribute.HtmlEncode" />
<MemberSignature Language="C++ CLI" Value="public:
 property bool HtmlEncode { bool get(); void set(bool value); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.Annotations</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.3.0.0</AssemblyVersion>
<AssemblyVersion>4.3.1.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.DataAnnotations</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets a value that indicates whether the field should be HTML-encoded.</summary>
<value>
<see langword="true" /> if the field should be HTML-encoded; otherwise, <see langword="false" />.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="NullDisplayText">
<MemberSignature Language="C#" Value="public string NullDisplayText { get; set; }" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0-pp" />
<MemberSignature Language="ILAsm" Value=".property instance string NullDisplayText" />
<MemberSignature Language="DocId" Value="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayText" />
<MemberSignature Language="VB.NET" Value="Public Property NullDisplayText As String" />
<MemberSignature Language="F#" Value="member this.NullDisplayText : string with get, set" Usage="System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayText" />
<MemberSignature Language="C++ CLI" Value="public:
 property System::String ^ NullDisplayText { System::String ^ get(); void set(System::String ^ value); };" />
<MemberSignature Language="C#" Value="public string? NullDisplayText { get; set; }" FrameworkAlternate="net-10.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netstandard-2.1-pp" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.Annotations</AssemblyName>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.3.0.0</AssemblyVersion>
<AssemblyVersion>4.3.1.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.DataAnnotations</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the text that is displayed for a field when the field's value is <see langword="null" />.</summary>
<value>The text that is displayed for a field when the field's value is <see langword="null" />. The default is an empty string (""), which indicates that this property is not set.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Sometimes a data field's value is stored as null values in the source. You can specify custom text to display for data fields that have a null value by setting the <xref:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayText%2A> property. If this property is not set, null field values are displayed as empty strings ("").
> [!NOTE]
> To convert an empty string field value to a null value, you must set the <xref:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.ConvertEmptyStringToNull%2A> property to `true`.
## Examples
The following example shows how to use the <xref:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayText%2A> to define a caption to display when the data field is `null`.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.DisplayFormatAttribute/CS/product.cs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.ComponentModel.DataAnnotations.DisplayFormatAttribute/VB/product.vb" id="Snippet2":::
]]></format>
</remarks>
<altmember cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.DataFormatString" />
<altmember cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.ConvertEmptyStringToNull" />
</Docs>
</Member>
<Member MemberName="NullDisplayTextResourceType">
<MemberSignature Language="C#" Value="public Type? NullDisplayTextResourceType { get; set; }" FrameworkAlternate="net-10.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netstandard-2.1-pp" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Type NullDisplayTextResourceType" />
<MemberSignature Language="DocId" Value="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayTextResourceType" />
<MemberSignature Language="VB.NET" Value="Public Property NullDisplayTextResourceType As Type" />
<MemberSignature Language="F#" Value="member this.NullDisplayTextResourceType : Type with get, set" Usage="System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayTextResourceType" />
<MemberSignature Language="C++ CLI" Value="public:
 property Type ^ NullDisplayTextResourceType { Type ^ get(); void set(Type ^ value); };" />
<MemberSignature Language="C#" Value="public Type NullDisplayTextResourceType { get; set; }" FrameworkAlternate="netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netstandard-2.0-pp" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.Annotations</AssemblyName>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.3.0.0</AssemblyVersion>
<AssemblyVersion>4.3.1.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.ComponentModel.DataAnnotations</AssemblyName>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="net-10.0;net-6.0;net-7.0;net-8.0;net-9.0">
<AttributeName Language="C#">[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]</AttributeName>
<AttributeName Language="F#">[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Type</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the <see cref="T:System.Type" /> that contains the resources for <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayText" />.
Using <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayTextResourceType" /> along with <see cref="P:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.NullDisplayText" />, allows the <see cref="M:System.ComponentModel.DataAnnotations.DisplayFormatAttribute.GetNullDisplayText" /> method to return localized values.</summary>
<value>To be added.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
</Members>
</Type>