Problems with data binding a radio button list

125 pts.
Tags:
Databinding
radio button list
I am trying to bind  a data reader value to a radio button list.

I am using VS2008 ASP 3.5 and SQL Server 2005. Below is my code and error message.

--Code--

 

Protected Sub tbx_CLnhssn_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbx_CLnhssn.TextChanged  



If Len(Trim(tbx_CLnhssn.Text)) = 9 Then

 

'Version 1.0 WORKS

cbx_CLpdb.Enabled =

True

cbx_CLwc.Enabled =

True

Session(

"ss_NHSSN") = tbx_CLnhssn.Text.ToString  



Dim ss_PIN As String = CType(Session.Item("PIN"), String)  



Dim conn As New SqlConnection() conn.ConnectionString = ConfigurationManager.ConnectionStrings _

(



"S82e033-eWC").ConnectionString  



Dim cmd As New SqlCommand("usp_testCL", conn) cmd.CommandType = CommandType.StoredProcedure

cmd.Parameters.AddWithValue(



"@NHSSN", tbx_CLnhssn.Text.ToString) cmd.Parameters.AddWithValue(



"@CL_EmpPin", ss_PIN.ToString)  



Dim rdr As System.Data.SqlClient.SqlDataReader conn.Open()

rdr = cmd.ExecuteReader()

 



' Populate the Control

 

While rdr.Read() cbx_CLpdb.Checked = rdr.GetValue(0)



'CL_PDB

cbx_CLwc.Checked = rdr.GetValue(1)

rbl_CLpdbICF.DataValueField = rdr.GetValue(2)

'rbl

rbl_CLprop.DataValueField = rdr.GetValue(3)

'rbl

 

End While

rdr.Close()

conn.Close()

 

End If

 

End Sub

---This is the error that I get

The radio button is not populated??



Software/Hardware used:
I am using VS2008 ASP 3.5 and SQL Server 2005

Answer Wiki

Thanks. We'll let you know when a new response is added.

Yeah, that was the first thing that I did. I have two adddtional controls that do get populated correctrly.

Discuss This Question: 7  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    What is the exact error message ? What is the line of code that generates the error ? Have you tried assigning a fixed field name to the DataValueField property of the radio button lists (i.e. without using your DataReader) ?
    69,045 pointsBadges:
    report
  • Neilo
    Thanks for getting back so quickly. The system does not generate a message but the error is the fact that the radiobutton list is not populated. The value for the radio buttons is 1 (Yes) and 0 (No). Store procedure passes an array form 0-3 or 4 items, the first two get populated properly but the other 2 do not and that is my problem. Any help is appreciated.
    125 pointsBadges:
    report
  • carlosdl
    I see 2 RadioButtonLists in your code: rbl_CLpdbICF and rbl_CLprop. Which one is not being populated ? Also, what happens if you try the suggestion from my previous post ?
    69,045 pointsBadges:
    report
  • Neilo
    Neither one of the two radioButtonList are being populated. I have change the value of both button to false and two true but I am not getting any results. It is as if the data reader is not passing the values or the syntax of how I assign the values is incorrect? Hope this help
    125 pointsBadges:
    report
  • carlosdl
    Have you checked that the stored procedure is in fact returning rows ? Also, the DataValueField property specifies the name of a field (from the data source) that provides the value of each list item (not the value itself ), so, the stored procedure in this case is supposed to return field names, not the values you want to assign to the radio buttons.
    69,045 pointsBadges:
    report
  • Neilo
    Carlos thanks for every thing, I found the solution to the problem, that was by passing datareader rsults to an interger variable and then pas again to the RadioButtonList the value of the variable as follows: Dim rst as Integer then add the the While read() (see above) ... rst=rdr.GetValue(2) End while rbl_CLpdbICF.SelectedValue=rst --- The above works, even if it isn't pretty Neil
    125 pointsBadges:
    report
  • carlosdl
    Great ! As I thought, your procedure was not returning field names, but values. Thanks for sharing your solution.
    69,045 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following