[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:
Dim myCmd As New SqlCommand
myCmd.CommandType = CommandType.StoredProcedure
' Set command to create your SQL statement
myCmd.CommandText = "up_GetPaperTypes"
' Set the database connection
myCmd.Connection = myCon
myCmd.Parameters.Add("@Jnl_Code", "BJ")
Dim dr As SqlDataReader
Try
dr = myCmd.ExecuteReader()
If dr.Read() Then
With DocType
.DataSource = dr
.DataValueField = dr.GetString(0)
.DataTextField = dr.GetString(1)
.DataBind()
End With
End If
Catch ex As Exception
' Record any exceptions and exit
litMsg.Visible = True
litMsg.Text = "<p><font color=""red""><b>An exception occurred: GetPaperTypes</b><br />" + ex.Message + "</font></p>"
Finally
dr.Close()
If myCon.State = ConnectionState.Open Then myCon.Close()
End Try
Re: Error Binding RadioButtonList
I've fixed it by doing this
VB Code:
Try
dr = myCmd.ExecuteReader()
Dim i As Int32 = 0
Do While dr.Read()
With DocType
.Items.Add(New ListItem(Convert.ToString(dr("Description")), Convert.ToString(dr("Type_Code"))))
If Convert.ToBoolean(dr("Default_Item")) Then
.SelectedIndex = i
End If
End With
i += 1
Loop
Catch ex As Exception