locked
setting a radio button value according to string returned from database. String is 'Yes' or 'No' RRS feed

  • Question

  • User1080700311 posted


    I have a radio button control on a web form. The members of my ListItem collection are
    assigned the following.

    Text  No
    Value 0

    Text  Yes
    Value 1


    So what I need to do, is to readd a varchar value from my database and if the column value returned equals 'Yes'
    then I need to select the radio button that has the assigned value of 1.

    Otherwise if the value read from the database is 'No', then I need to select the radio button assigned a value
    of 0

         

    So how can I set the value for my radio button? I experimented and could not figure it out. Possibly someone
    could help me. The 'Yes' or 'No' value is stored in my database in the field ds.Tables("employee").Rows(0).Item("answer")


    So I tried something like this which is not correct:

              RadioButtonList1.Items.FindByValue(ds.Tables("employee").Rows(0).Item("answer") = "Yes").Equals(True)

    Friday, July 24, 2009 4:21 PM

Answers

  • User-364289655 posted

    If  ds.Tables("employee").Rows(0).Item("answer") = "Yes" then

            RadioButtonList1.SelectedIndex = 1

    else

          RadioButtonList1.SelectedIndex = 0

    end if

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 24, 2009 4:31 PM
  • User533502567 posted

    So I tried something like this which is not correct:

       RadioButtonList1.Items.FindByValue(ds.Tables("employee").Rows(0).Item("answer") = "Yes").Equals(True)

    
    

    Try like this..

    'In VB.Net
    RadioButtonList1.Items.FindByValue(ds.Tables("employee").Rows(0).Item("answer")).Selected = True
    
    //In C#
    RadioButtonList1.Items.FindByValue(ds.Tables("employee").Rows(0).Item("answer")).Selected = true;


     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 24, 2009 5:09 PM

All replies

  • User-364289655 posted

    If  ds.Tables("employee").Rows(0).Item("answer") = "Yes" then

            RadioButtonList1.SelectedIndex = 1

    else

          RadioButtonList1.SelectedIndex = 0

    end if

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 24, 2009 4:31 PM
  • User533502567 posted

    So I tried something like this which is not correct:

       RadioButtonList1.Items.FindByValue(ds.Tables("employee").Rows(0).Item("answer") = "Yes").Equals(True)

    
    

    Try like this..

    'In VB.Net
    RadioButtonList1.Items.FindByValue(ds.Tables("employee").Rows(0).Item("answer")).Selected = True
    
    //In C#
    RadioButtonList1.Items.FindByValue(ds.Tables("employee").Rows(0).Item("answer")).Selected = true;


     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 24, 2009 5:09 PM