PDA

View Full Version : Display Multiple Values in DropdownList Item


eRad
11-22-2004, 02:54 PM
Say i have an ASP.NET dropdownlist sourced from a Departments table, and i bind the textfield to be Department, and the valuefield to be ID.

I want the text to actually show both the ID and the department name. Aside from just appending them together in the database, i found a solution here http://www.dotnetjunkies.com/Article/D7108B11-7BB6-4196-8D88-D78A0AE5092B.dcik

i used the method of creating a new field within the SQL.. however when i tried it, i got an error: "Exception Details: System.InvalidOperationException: The provider could not determine the Double value. For example, the row was just created, the default for the Double column was not available, and the consumer had not yet set a new Double value."

here is my string:
SELECT ID,ID + ' - ' + Department AS Cost_Centre FROM Departments

any ideas?

rdove
11-22-2004, 03:49 PM
Thats doing it the hard way.


Dim liAdd as ListItem

While dr.Read
liAdd = New ListItem
liAdd.Value = dr("ID")
liAdd.Text = dr("ID") & " - " & dr("DeptName")
dropdownlist1.Items.Add(liAdd)
End While
dr.Close

eRad
11-23-2004, 09:51 AM
well i saw that as the other method... but this one involved just changing my SQL, whereas that method involves changing all my reading code.

No biggie... out of curiosity though, if i WAS to use the first way, what did i do wrong?

afterburn
11-23-2004, 10:43 AM
I would derive the code off from the Base Control then customize output using HtmlWriter.