Results 1 to 2 of 2

Thread: Databinding Dropdown list to a datareader

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2003
    Location
    Ft. Lauderdale, FL
    Posts
    33

    Question 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!
    Rich J Defilippo

  2. #2

    Thread Starter
    Member
    Join Date
    Jan 2003
    Location
    Ft. Lauderdale, FL
    Posts
    33

    Solution ....

    When I remove the While dataReader.Read() Condition and simply retrieve the datareader and then bind the control to it it works fine...

    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)
                    ddlDocTypes.DataBind()
                End If
    Rich J Defilippo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width