How to dynamically select RadioButtonList value for Yes or No from the database
ASP.NET
1
Posts
1
Posters
2
Views
1
Watching
-
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