Databases Reference
In-Depth Information
NOTE
It is not necessary to specify both ShortName and Name properties of the
DisplayAttribute if they have the same value. If the ShortName is not specified,
Dynamic Data automatically uses the Name instead.
Prompt Annotation
The DisplayAttribute includes several additional properties that can be used to further
tune the appearance of the entity property in dynamically generated pages, although not
all of them are supported by the Dynamic Data out of the box. In particular, the Prompt
property of the DisplayAttribute could be used to provide a custom string for use in
form labels, similar to how the ShortName property specifies display name for grid column
headers. To implement this, you can simply change the dynamic entity template,
Default.ascx , to use the prompt string if it was specified and otherwise fall back to using
the display name string, as shown next:
protected void Label_Init(object sender, EventArgs e)
{
var label = (Label)sender;
label.Text = this.currentColumn.Prompt
?? this.currentColumn.DisplayName;
}
NOTE
Here and in the rest of this chapter, assume dynamic entity templates Default.ascx ,
Default_Edit.ascx , and Default_Insert.ascx have been combined into a single,
multimode template, Default.ascx , as discussed in Chapter 10, “Building Custom
Forms.”
This code first appeared in Listing 10.6 and was discussed in detail in Chapter 10. The
Label_Init method handles the Init event of the Label control the entity template
generates for each entity property. The currentColumn field contains a reference to the
MetaColumn object describing the current entity property for which a label and a data
entry control are being generated. The original version of this code initialized the label
Text using only the DisplayName property of the MetaColumn object. The new version just
shown first tries to initialize the label text using the Prompt before falling back to the
DisplayName .
 
Search WWH ::




Custom Search