dtempleton
MIS
Using VS 2003 and SQL Server 2000
I have a master table that uses a lookup table. Rather than deleting records within the lookup table, it has an "IsActive" column that is changed to FALSE. There is no requirement that the master table be updated before making a record in the lookup table inactive.
Now I want to create an edit page for the master table. I'd like to populate a DropDownList with all of the active records, making sure to include the master table's current value even if it is inactive.
The code I have now works, but it seems sloppy. The SQL stored procedure that returns the master table record also returns the lookup table's description (masterTableValue, lookupTableText). After trying to set the DropDownList to the correct value, I check to make sure it equals what the master table has. If not, I add the value to the top of the list.
The question is, "What is the best-practices method to ensure that the current value exists within the DropDownList?" SQL and .NET recommendations are both welcome.
Thanks in advance,
Dave
I have a master table that uses a lookup table. Rather than deleting records within the lookup table, it has an "IsActive" column that is changed to FALSE. There is no requirement that the master table be updated before making a record in the lookup table inactive.
Now I want to create an edit page for the master table. I'd like to populate a DropDownList with all of the active records, making sure to include the master table's current value even if it is inactive.
The code I have now works, but it seems sloppy. The SQL stored procedure that returns the master table record also returns the lookup table's description (masterTableValue, lookupTableText). After trying to set the DropDownList to the correct value, I check to make sure it equals what the master table has. If not, I add the value to the top of the list.
Code:
if (ddlLookup.SelectedValue != masterTableValue)
{
ddlLookup.Items.Insert(0, new ListItem(lookupTableText, masterTableValue);
ddlLookup.SelectedIndex = 0;
}
The question is, "What is the best-practices method to ensure that the current value exists within the DropDownList?" SQL and .NET recommendations are both welcome.
Thanks in advance,
Dave