Using Expression Property to create Columns with Dynamic Values


I noticed in many database designs with columns which will keep some dynamic values. The fact is that those dynamic values may alter at any time and then the user wants to change them in the database also. My opinion is that dynamic values should handle with dynamic columns whenever possible. We can easily do it from front end in C# using the expression property of the data column. Just download the code along with this, as then there may not be a need for further explanation.

Data column has a property named expression. Normally we can assign a value to this property as a relation with other columns and display a value which may depend on values from other columns. Here I created 3 dynamic columns named, PF, Bonus and Total Amount. First 2 columns PF and Bonus have expressions like their value will generate from a column named basic salary. I.e. user will enter the PF and Bonus rates from front end and corresponding PF and Bonus columns will automatically generate using the expression property on them. The last column Total Amount will generate using an expression like (basic salary - PF + Bonus), otherwise that is the expression assigned to that last column and that column will generate a value dynamically which will satisfy this equation. Finally all items will bind to a grid view. Cool isn't it? I used Visual Studio 2005 with web project template for the example along with this article.