|
Customizing the Appearance of a DataGrid Column Value
By:
Scott Mitchell
|
Created: 2003-05-08
|
Last Updated: 2003-05-15
|
Printer-Friendly Version
One of the many benefits of the DataGrid is the ease with which you can have the contents of a database table displayed. For example, to display the contents of a database column, you can simply use a BoundColumn with its DataField property set to the name of the database field whose value you want to appear in the column.
However, what if you find that the value in the database field is not the precise value you want displayed?
For example, imagine that you wanted to display a database table named
Perhaps the value of the
A DataGrid helper function is a function that is used in a TemplateColumn and takes in an arbitrary number of parameters and returns a string. The string returned by the function is what is displayed in the TemplateColumn. For our example, our helper function will take in one parameter - the gener of the employee - and return a string: either "Male" or "Female", depending upon the value passed in. First, let's create our helper function, and then we'll look at how to have it called from the DataGrid's TemplateColumn. The following function accepts a string input and returns the appropriate gender string:
Now, we need to see how to call this DataGrid helper function from our TemplateColumn. Essentially, you have to use DataBinding
syntax to call the function, passing in the value of the
That's all there is to it!
|
Home | FAQs | Articles | About | My Blog | Buy the Book!
Copyright 2006, Scott Mitchell. All Rights Reserved.