Knowledge Base
 
 
Knowledge Base Forum
Search knowledge base:

HOWTO: Change the display text for the foreign key values
Monday, 09 April 2007
When a database field being edited is a foreign key field then all the rows from the parent table are displayed. The article explains how to customize the display text for the FK values.

SUMMARY

When a database field being edited is a foreign key field then all the rows from the parent table are displayed. The user chooses one of the parent rows and its value is saved as a value for the field being edited. By default the parent table rows are represented by the value of their columns which participate in the foreign key relation. The article explains how to customize the display text for the FK values.

MORE INFORMATION

Lets consider a simple example. The Products database table has a column CategoryID, which is a foreign key to the CategoryID column of the Categories database table. Categories table has the following columns: CategoryID, CategoryName, Description, Picture .In the default case the user interface will display a list of numbers which are the CategoryID values for the rows in the Categoies table.



To change the display text for the values you should specify a RowCaption Expression for the Categories table. The expression can contain column names from the columns of the FK parent table. In our case this will be the columns of the Categories table. An appropriate expression is "CategoryName+'( '+Description +' )'". The syntax of the expression is described here - MSDN - DataColumn.Expression Property.

There are two places where you can specify the RowCaption Expression. Either in a Global ASP.NET resource or in the database table's extended properties.

Global ASP.NET resource

Open the .resx file which is specified in the smartDBforms.NET/resourceClassKey attribute in Web.config. Enter a new value. The name of the value should be like <TableName>.RowCaptionExpression. In our case this will be "Categories.RowCaptionExpression" . The value will be "CategoryName+'( '+Description +' )'".

Database extended property

Open MS SQL Management Studio, find the table and right-click on it. Select the Properties menu item. In the Table Properties dialog select the Extended Properties page. Enter a new value. The name of the value should be SDBF_RowCaptionExpression.

CONCLUSION

After the change is applied the user interface for the CategoryID field will look like this:

You can find more information about smartDBforms.NET Caption and Description configuration in the online documentation.


Page Options: format for printing  Format for Printer

How would you rate the quality of this content?
Poor - - Excellent
Comments? 
Overall Rating:
Comments Left:
Left on Saturday, 19 April 2008 by Anonymous
Comments:
No ratings available.
Left on Wednesday, 30 May 2007 by Anonymous
Comments: useful
Copyright 2006-2008 Adillis Terms Of Use Feedback Contact Us