Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to dynamically select RadioButtonList value for Yes or No from the database

How to dynamically select RadioButtonList value for Yes or No from the database

Scheduled Pinned Locked Moved ASP.NET
databasesql-servertutorialquestion
1 Posts 1 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samflex
    wrote on last edited by
    #1

    We have a RadioButonList with a Yes or No choice, however, we would like the choices to be dynamically populated from the database. In other words, we have a column name called IsVetoVote. It is Bit datatype with 1 for Yes or 0 for No value. If a user queries the database for a particular proposal to see if this proposal has been voted on, if the answer is yes (or 1), we would like the RadioButtonList Yes box to the checked. If no (or 0), then the RadioButtonList No box to be checked. My code below is not giving me either Yes or No value. When I run the query portion of the code in SSMS, I get the correct result of either 1 or 0 but the RadioButtonList is not getting checked. Any ideas what could be wrong with the code?

    myConnection.Open()
    Dim strSQL As String
    
    strSQL = "Select IsVetoVote from Ballots where choices Like '%' + @vetono + '%'"
    Dim command As SqlCommand = New SqlCommand(strSQL, myConnection)
    With command.Parameters
        .Add(New SqlParameter("@vetono", SqlDbType.NVarChar).Value = location.Replace("'", "''").Trim())
    End With
    
    'Fill a dataset with data from the Ballots table.
    Dim ds As New DataSet
    Dim da As New SqlDataAdapter(strSQL, myConnection)
    da.Fill(ds, "tblreturns")
    
    If (ds.Tables(0).Rows.Count > 0) Then
           Else
        Dim returns As String = (ds.Tables("tblreturns").Rows(0).Item("IsVetoVote"))
    
        For Each r As ListItem In VetoVote.Items
            If r.Value = returns Then
                r.Selected = True
            End If
        Next
    
    End If
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups