Results 1 to 2 of 2

Thread: [RESOLVED] Error Binding RadioButtonList

  1. #1

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Resolved [RESOLVED] Error Binding RadioButtonList

    Hi,

    I'm trying to bind a radiobuttonlist to a db table but am getting the following error

    DataBinder.Eval: 'System.Data.Common.DbDataRecord' does not contain a property with the name Full Paper

    Full Paper is one of the text values from my dataReader??

    Here is my HTML
    Code:
    <td>Document type:</td>
    <td><asp:radiobuttonlist id="DocType" runat="server" ></asp:RadioButtonList></td>
    CodeBehind - OnLoad Event
    VB Code:
    1. Dim myCmd As New SqlCommand
    2. myCmd.CommandType = CommandType.StoredProcedure
    3. ' Set command to create your SQL statement
    4. myCmd.CommandText = "up_GetPaperTypes"
    5. ' Set the database connection
    6. myCmd.Connection = myCon
    7. myCmd.Parameters.Add("@Jnl_Code", "BJ")
    8.  
    9. Dim dr As SqlDataReader
    10.  
    11. Try
    12.     dr = myCmd.ExecuteReader()
    13.     If dr.Read() Then
    14.     With DocType
    15.         .DataSource = dr
    16.         .DataValueField = dr.GetString(0)
    17.         .DataTextField = dr.GetString(1)
    18.         .DataBind()
    19.     End With
    20.     End If
    21. Catch ex As Exception
    22.     ' Record any exceptions and exit
    23.     litMsg.Visible = True
    24.     litMsg.Text = "<p><font color=""red""><b>An exception occurred: GetPaperTypes</b><br />" + ex.Message + "</font></p>"
    25. Finally
    26.     dr.Close()
    27.     If myCon.State = ConnectionState.Open Then myCon.Close()
    28. End Try

  2. #2

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Re: Error Binding RadioButtonList

    I've fixed it by doing this

    VB Code:
    1. Try
    2.     dr = myCmd.ExecuteReader()
    3.     Dim i As Int32 = 0
    4.     Do While dr.Read()
    5.     With DocType
    6.         .Items.Add(New ListItem(Convert.ToString(dr("Description")), Convert.ToString(dr("Type_Code"))))
    7.         If Convert.ToBoolean(dr("Default_Item")) Then
    8.         .SelectedIndex = i
    9.         End If
    10.     End With
    11.     i += 1
    12.     Loop
    13. Catch ex As Exception

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