Deborah's Developer MindScape






         Tips and Techniques for Web and .NET developers.

July 19, 2010

SL/RIA/POCO: Field Ordering

Filed under: ASP.NET RIA Services,C#,Silverlight,VB.NET @ 5:30 pm

The prior post here detailed how to build a Silverlight application using WCF RIA Services and your own plain old CLR objects (POCOs). That application displayed the data in a grid and allowed updates using a set of labels and textboxes. But the order of the fields was alphabetical, which is rarely the order that you want.

image

So you could spend some time in the XAML, reordering the controls.

OR, you could add a few more attributes to your business object in your business layer and the fields will be ordered as you want.

Use the DisplayAttribute to:

  • Define a field name different from the business object property name.
  • Define a short name for use in the grid.
  • Define a field to use as a watermark.
  • Define the order of the field when building the UI.
  • Define the resource type if the strings are defined in a resource file.

First, be sure to import the System.ComponentModel.DataAnnotations namespace. Then add the DisplayAttribute to the properties as shown in this example.

In C#:

[Display(Order=1, Description="Customer’s last name", ShortName="LName", Name="Name (Last)")]
public string LastName { get; set; }

In VB:

<Display(Order:=1, Description:="Customer’s last name", ShortName:="LName", Name:="Name (Last)")>
Public Property LastName() As String

The result looks like this:

image

Notice the use of the ShortName in the grid column header and of the Name in the field label. But more importantly for this column, notice the order of the fields both in the grid and in the data entry form.

Use this technique to define the field ordering before you drag and drop a grid or data entry form onto your Silverlight page.

Enjoy!

1 Comment

  1.   Water Damage Restoration Software — July 8, 2011 @ 2:41 pm    Reply

    Nice article on SL4. Nice and short. Visual Studio 2010/SL4 really makes it easier to handle data and databases…

RSS feed for comments on this post. TrackBack URI

Leave a comment

© 2021 Deborah's Developer MindScape   Provided by WPMU DEV -The WordPress Experts   Hosted by Microsoft MVPs