I am trying to create a user friendly drop down using the following columns:
LNAME, FNAME, USERID
Here is my SelectCommand:
SELECT ISNULL(LNAME,'') + ', ' + ISNULL(FNAME,'') + ' (' + ISNULL(USERID,'') + ') ' AS FullName FROM USER ORDER BY FullName
The result is:
LNAME, FNAME (USERID)
This is what I want. I am trying to set the DataValueField to the USERID for use in SelectedIndexChanged. Right now it only works when DataValueField is set to FullName. I receive the following error when setting it to USERID:
DataBinding: ‘System.Data.DataRowView’ does not contain a property
with the name ‘USERID’.
I need to use the USERID for the next step. Is there a way to extract USERID from the alias in this SELECT statement?
Change your SQL to separate value and label (text)
Then you bind
The example on MSDN shows this: the value has no spaces eg “Dark Khaki” vs “DarkKhaki”