Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a DropDownList when the source table has an IsActive column

Status
Not open for further replies.
May 12, 2004
89
0
0
US
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.
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
 
>>The question is, "What is the best-practices method to ensure that the current value exists within the DropDownList?"

sorry dude, i am confused.

what do u mean by current value? u already seem to be inserting it in the line:

ddlLookup.Items.Insert(0, new ListItem(lookupTableText, masterTableValue);


could u give me some sample data???

Known is handfull, Unknown is worldfull
 
I am inserting it in that line, but doing it that way seems sloppy.
 
why do u feel its sloppy? is it inbetween some loop?

the other alternative would be to do it in the SP / SQL itself. that would be the best way.

something like this:


select lookup.* from
mastertable inner join lookup on mastertable.Field=Lookup.Field
UNION
select * from lookup where IsActive=False

this will return back data that u want...



Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top