I am using Visual Studio 2005 to build a website using ASP.NET and VB.NET. It is accessing data on SQL Server 2005.
I have a form (actually it is in a wizard) that needs data populated from a sqldatareader.
This all works for the first two steps in the wizard, but doesn't populate all of the fields for the third. In fact, the only fields it doesn't populate are the dropdownlists.

' This first one works fine, but is on the second step of the wizard
If (dtrReader("OS_ID")) Is System.DBNull.Value Then
AddSystemOS.SelectedValue = Nothing
Else
Dim OS As New TextBox
OS.Text = dtrReader("OS_ID")
AddSystemOS.SelectedValue = OS.Text
End If
'This one doesn't work at all, and is on the third step
If (dtrReader("OPENEDBY_EMPLOYEE_ID")) Is System.DBNull.Value Then
AddProblemTicketCreatedBy.SelectedValue = Nothing
Else
Dim CreatedBy As New TextBox
CreatedBy.Text = dtrReader("OPENEDBY_EMPLOYEE_ID")
AddProblemTicketCreatedBy.SelectedValue = CreatedBy.Text
End If

I would also like to point out that other controls on the third step are working (checkboxes, and textboxes). It is only the dropdownlists that are not.

Also, something else strage I noticed once I started doing this, the wizard no longer starts on the first step. Instead it starts on the second step.

Thanks,
J'Tok

Featured Replies in this Discussion

double click on your dropdownlist and change the end text of the sub from .selectedindexchanged to .databound then write your code that sets the selected value to the cell value from the database. if you are doing it on page load, call a dropdownlistX.databind() to make this code function on load.

Awesome! That pretty much fixed it. However, I still have one dropdownlist that isn't working still. The catch is that this one isn't databound. Of course, in this case, it still needs to be populated by the database's value. I am using the same type of statement as above.

- J'Tok

Edit:
I'm actually doing it a little different, now that you showed me how to make it work.
Here:

If (dtrReader("OPENEDBY_EMPLOYEE_ID")) Is System.DBNull.Value Then
AddProblemTicketCreatedBy.SelectedValue = Nothing
Else
AddProblemTicketCreatedBy.SelectedValue = dtrReader("OPENEDBY_EMPLOYEE_ID")
End If

You can also update your database type to nvarchar(XXX). This is basically a floating length and will not have any spaces at the end.

ya, I debated doing that, but using nvarchar wasn't worth the resource cost for what I was doing. Setting a static length in this scenario uses much less since I only allow for up to three characters, and storing the extra data for each field to have it reduce it for the few that are only 2 seemed a waste.

Long story short, I was going for a certain amount of performance/efficiency.