tags:

views:

124

answers:

2

I used the subsonic generator to create some aspx pages, It works fine. On some of the pages it automaticaly generated the dropdown boxes for foreign key values. How Can change that value in the load drops code? Or where I need to change it.

For instance I have a workers table and a workersweek table. The workers table has a workerid,firstname and lastname field and the workersweek has a workerID field. The generator automatically set it up to show the firstname in the dropdown. I want to change the value to be both firstname and lastname.

I am sure I will have to add code that does something like firstname + " " + Lastname.

I am just not sure where to do it withing the code that was generated. I see the load drops sub, but it does not seem like that is the one I need to modify.

A: 

If it loads from a foreign key then it loads from a database table.

If you need to concat fields in the query, try making a view with the fields concatenated. e.g. select fName + ' ' + lName as FullName from table

Then in the code behind for the aspx page, select that from the view to load the combobox.

Rick Ratayczak
A: 

Alternatively try using the 'partial' class functionality to create a new bind-able property. This works for me a treat and has the added bonus of consistent presentation of data through out my apps (With the added bonus of not having to change anything in the database - helpful if you have DBA's from hell that demand 18 levels of change control to get anything done.)

So if your tables class file is "workers.cs" and contains a class called "workers.cs", simply create another class file called "workers_custom.cs" (use your own conventions for working with partial classes) that contains the rest of the partial class, in this case something like:

using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace YOURCOMPANY.YOURSYSTEM.YOURDAL   {

    public partial class Workers {

        [Bindable(true)]
        public string displayWorkersName {
            get {
                try {
                    return this.fName + ", " + this.lName;
                } catch {
                    //Your own error handling here
                    return IsNew ? "##New##" : "##Undefined##";
                }
            }
        }

    }
}

(Note you will need to change the bound property member of your control to your new property - in this case: "displayWorksName")

Joe