Databinding Dropdown list to a datareader
Hello,
I'm having an interesting problem. I'm databinding a dropdownlist to a SQL Datareader. Everything works fine -- EXCEPT the first item is always ignored or skipped!!
Why does this happen and how do I resolve this issue?
Here is a code sample: Note: the GetTemplates method just creates a connection and uses data access blocks to return a SQL datareader.
Code:
Dim rdrData As SqlDataReader = BO_EmailInterface.GetData.GetTemplates(CStr(Session("strServer")), DeptID)
If Not rdrData Is Nothing Then
ddlDocTypes.DataSource = rdrData
ddlDocTypes.DataTextField = rdrData.GetName(1)
ddlDocTypes.DataValueField = rdrData.GetName(0)
While rdrData.Read()
ddlDocTypes.DataBind()
End While
End If
In this case only one record is returned - verified this in debuging - however nothing is displayed - if more than one record is returned the first is always ignored!!
Any help and/or explanations would be much appreciated!!
Thanks!