Display Multiple Values in DropdownList Item

liunx

Guest
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 <!-- m --><a class="postlink" href="http://www.dotnetjunkies.com/Article/D7108B11-7BB6-4196-8D88-D78A0AE5092B.dcik">http://www.dotnetjunkies.com/Article/D7 ... 5092B.dcik</a><!-- m -->

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?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.Closewell 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?I would derive the code off from the Base Control then customize output using HtmlWriter.
 
Back
Top