views:

1023

answers:

2

I am writing a site that uses strongly typed datasets.

The DBA who created the table made gave a column a value that represents a negative. The column is 'Do_Not_Estimate_Flag' where the column can contain 'T' or 'F'. I can't change the underlying table or the logic that fills it. What I want to do is to add a 'ESTIMATION_ALLOWED' column to the DataRow of my strongly typed DataSet. I have done this using the partial class that I can modify. (There is the autogenerated partial class and the non autogenerated partial class that I can safely modify.) The logic is in a property in the partial class. The trouble is that when the value is loaded ala

<%#DataBinder.Eval(Container.DataItem, "ESTIMATION_ALLOWED")%>

it goes straight to the underlying DataRow ignoring my property. How can I best achieve the desired result?

here is my code:

partial class MyFunkyDataTable {

        private System.Data.DataColumn columnESTIMATION_ALLOWED;
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public System.Data.DataColumn ESTIMATION_ALLOWEDColumn
        {
            get
            {
                return columnESTIMATION_ALLOWED;
            }
        }

        public override void EndInit()
        {


            //init class
            columnESTIMATION_ALLOWED = new System.Data.DataColumn("ESTIMATION_ALLOWED", typeof(string), null, global::System.Data.MappingType.Element);
            Columns.Add(columnESTIMATION_ALLOWED);
            columnESTIMATION_ALLOWED.ReadOnly = true;

            //init Vars
            columnESTIMATION_ALLOWED = Columns["ESTIMATION_ALLOWED"];
            base.EndInit();
        }




    }
    partial class MyFunkyRow 
    {
        public string ESTIMATION_ALLOWED
        {
            get
            {
                if(DO_NOT_EST_FLAG == "N")
                {
                    return "Yes";
                }
                return "No";
            }
        }
    }
+1  A: 

The DataBinder will see that you're binding to a DataRow and use its fields rather than any property you define.

You could create a method to do what you want, e.g.:

<%#FormatFlag(DataBinder.Eval(Container.DataItem, "Do_Not_Estimate_Flag" ))%>

where you have a method:

protected string FormatFlag(object doNotEstimateFlag)
{
    if (doNotEstimateFlag.ToString() == "N") return "Yes";
    return "No";
}

An alternative is to modify the query that fills your DataTable. For example, you could have a column "ESTIMATE_ALLOWED" in your typed dataset. The query that fills it would look something like the following (database dependent, this is for SQL Server):

SELECT
   ...
   CASE WHEN Do_Not_Estimate_Flag = 'N' THEN 'Yes' ELSE 'No' END ESTIMATE_ALLOWED,
   ...
FROM
   ...
Joe
A: 

If I recall, ST datasets datarows are implmented in partial classes. So you might add the functionality you need in the partial class off the main ST dataset row class.

boomhauer