Reputation: 364
I'm creating a form that has a dropdownlist
for dept.
The place i work for has only a field with like 50 departments in the field itself. If i query that field and return it to a string on the CS file, how can i break the different departments all up to binding to the ddl?
Some departments have two names that have a space in between the words.
Upvotes: 1
Views: 134
Reputation: 1028
Anything short of normalizing the table will result in something of a hack. I would consider creating a new table: Department. There you store each of the values in its own row. This will make data retrieval and, like @Vulcronos said, joining on another table much easier.
Upvotes: 2
Reputation: 152614
The "right" answer is to modify the source to properly delimit the department names.
If you can't do that, and if the list is somewhat static you could use an "exception list" to indicate departments that should stay together:
string[] knownDepartments = new []
{
"Human Resources",
"Community Services",
etc.
};
then just extract those from the source string before parsing:
foreach(string dept in knownDepartments)
departments = departments.Replace(dept,"");
then parse the remaining departments (and tack on the known departments):
var departmentList = departments.Split(' ')
.Union(knownDepartments)
.ToList();
Upvotes: 0