populating radiobuttonlist from database programmatically

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default populating radiobuttonlist from database programmatically

    I store radiobuttonlist values in the db using the string value of the radio
    button item value. (nvarchar)

    I am creating an edit functionality on the asp.net form so that when I reuse
    my dataentry form for edit, I search the database for the row containing the
    data I want, and then populate all the form fields.

    here is what I have so far. What I don't know what to do is for cases where
    a dirty database has no associated value for the radiobuttonlist, I don't
    want to select anything. How do I do that?
    ***************
    dbaseReturnValue = arParms(17).Value.ToString() 'get value from returned
    stored procedure call.
    For Each li In RadioButtonList.Items
    i += 1
    If (RadioButtonList.Value = dbaseReturnValue Then //but Value is
    not a valid member. what do i use?
    RadioButtonList.SelectedValue = dbaseReturnValue
    li.Selected = True
    else
    RadioButtonList.SelectedValue = ???????????
    End If
    Next
    ***************
    Thank you,
    Greg Hazzard


    Hazzard Guest

  2. Similar Questions and Discussions

    1. Populating Drop Down Boxes from a database
      We moved our wesite from a Box running Coldfusion 4.0 to a box running Coldfusion MX. We populate some drop down boxes with information from a...
    2. Web Form Populating Database
      Publisher 2003. Web form set to save the data in a comma-delimeted text file on my web server. Form working well, I'm able to use the wizard in...
    3. populating text from database
      I am trying to populate multiple textboxes from an Access database. I am trying to write code to generate the appropriate number of textboxes...
    4. Populating three list boxes from the database
      Can anybody help? I need to have three list boxes automatically populating each other, (ie when region is selected from the first listbox, it will...
    5. Populating another database with records from an asp page.
      Apologies for the length of this mail but code is included. Have a page that pulls data from one database & displays the results, using a loop to...
  3. #2

    Default Re: populating radiobuttonlist from database programmatically

    Thank you Justin ! Of course, it sets it to a value out of the range of the
    valid values.
    And what about the comparison of the database value, eg. "radiobuttonvalue1"
    ?
    Which property do I use to iterate through the list of radiobutton item
    values to compare with say, "radiobuttonvalue1?" Is it
    radionbuttonlist.items.??? or
    radiobutton.items.searchbyvalue("radiobuttonvalue1 ")..

    thank you,
    Greg

    "S. Justin Gengo" <gengoj@krause.com> wrote in message
    news:vh5cqv4utha44@corp.supernews.com...
    > Hazzard,
    >
    > Have you tried:
    >
    > RadioButtonList.SelectedIndex = -1
    >
    > I hope this helps.
    >
    > Justin
    >
    >
    > "Hazzard" <hazz@sonic.net> wrote in message
    > news:uYZa2fgSDHA.1688@TK2MSFTNGP11.phx.gbl...
    > > I store radiobuttonlist values in the db using the string value of the
    > radio
    > > button item value. (nvarchar)
    > >
    > > I am creating an edit functionality on the asp.net form so that when I
    > reuse
    > > my dataentry form for edit, I search the database for the row containing
    > the
    > > data I want, and then populate all the form fields.
    > >
    > > here is what I have so far. What I don't know what to do is for cases
    > where
    > > a dirty database has no associated value for the radiobuttonlist, I
    don't
    > > want to select anything. How do I do that?
    > > ***************
    > > dbaseReturnValue = arParms(17).Value.ToString() 'get value from
    returned
    > > stored procedure call.
    > > For Each li In RadioButtonList.Items
    > > i += 1
    > > If (RadioButtonList.Value = dbaseReturnValue Then //but Value
    is
    > > not a valid member. what do i use?
    > > RadioButtonList.SelectedValue = dbaseReturnValue
    > > li.Selected = True
    > > else
    > > RadioButtonList.SelectedValue = ???????????
    > > End If
    > > Next
    > > ***************
    > > Thank you,
    > > Greg Hazzard
    > >
    > >
    >
    >

    Hazzard Guest

  4. #3

    Default Re: populating radiobuttonlist from database programmatically

    Greg,

    '---This code seems like more work but I've found it to be the fastest way
    to iterate

    ' through a loop because it calls on less objects

    Dim ItemCount, ItemLoop As Int32

    ItemCount = RadioButtonList.Items.Count - 1

    For ItemLoop = 0 To ItemCount

    If RadioButtonList.Items(ItemLoop).Value = dbaseReturnValue Then

    RadioButtonList.SelectedIndex = ItemLoop

    Exit For

    End If

    Next



    Justin





    "Hazzard" <hazz@sonic.net> wrote in message
    news:OtT7vShSDHA.1684@TK2MSFTNGP11.phx.gbl...
    > Thank you Justin ! Of course, it sets it to a value out of the range of
    the
    > valid values.
    > And what about the comparison of the database value, eg.
    "radiobuttonvalue1"
    > ?
    > Which property do I use to iterate through the list of radiobutton item
    > values to compare with say, "radiobuttonvalue1?" Is it
    > radionbuttonlist.items.??? or
    > radiobutton.items.searchbyvalue("radiobuttonvalue1 ")..
    >
    > thank you,
    > Greg
    >
    > "S. Justin Gengo" <gengoj@krause.com> wrote in message
    > news:vh5cqv4utha44@corp.supernews.com...
    > > Hazzard,
    > >
    > > Have you tried:
    > >
    > > RadioButtonList.SelectedIndex = -1
    > >
    > > I hope this helps.
    > >
    > > Justin
    > >
    > >
    > > "Hazzard" <hazz@sonic.net> wrote in message
    > > news:uYZa2fgSDHA.1688@TK2MSFTNGP11.phx.gbl...
    > > > I store radiobuttonlist values in the db using the string value of the
    > > radio
    > > > button item value. (nvarchar)
    > > >
    > > > I am creating an edit functionality on the asp.net form so that when I
    > > reuse
    > > > my dataentry form for edit, I search the database for the row
    containing
    > > the
    > > > data I want, and then populate all the form fields.
    > > >
    > > > here is what I have so far. What I don't know what to do is for cases
    > > where
    > > > a dirty database has no associated value for the radiobuttonlist, I
    > don't
    > > > want to select anything. How do I do that?
    > > > ***************
    > > > dbaseReturnValue = arParms(17).Value.ToString() 'get value from
    > returned
    > > > stored procedure call.
    > > > For Each li In RadioButtonList.Items
    > > > i += 1
    > > > If (RadioButtonList.Value = dbaseReturnValue Then //but
    Value
    > is
    > > > not a valid member. what do i use?
    > > > RadioButtonList.SelectedValue = dbaseReturnValue
    > > > li.Selected = True
    > > > else
    > > > RadioButtonList.SelectedValue = ???????????
    > > > End If
    > > > Next
    > > > ***************
    > > > Thank you,
    > > > Greg Hazzard
    > > >
    > > >
    > >
    > >
    >
    >

    S. Justin Gengo Guest

  5. #4

    Default Re: populating radiobuttonlist from database programmatically

    Thank you Justin! It even floats over a dirty database. Clean algorithm.
    _greg
    ************************************
    arReturnParms(x) = arParms(x).Value.ToString() 'value returned from
    database stored procedure.
    RadioButtonList.SelectedIndex = -1 'no radio buttons
    checked
    ItemCount = RadioButtonList.Items.Count - 1
    For ItemLoop = 0 To ItemCount
    If RadioButtonList.Items(ItemLoop).Value = arReturnParms(x) Then
    'unless there is a match
    RadioButtonList.SelectedIndex = ItemLoop
    Exit For
    End If
    Next
    ******************************

    "S. Justin Gengo" <gengoj@krause.com> wrote in message
    news:vh5hh645ojc86e@corp.supernews.com...
    > Greg,
    >
    > '---This code seems like more work but I've found it to be the fastest way
    > to iterate
    >
    > ' through a loop because it calls on less objects
    >
    > Dim ItemCount, ItemLoop As Int32
    >
    > ItemCount = RadioButtonList.Items.Count - 1
    >
    > For ItemLoop = 0 To ItemCount
    >
    > If RadioButtonList.Items(ItemLoop).Value = dbaseReturnValue Then
    >
    > RadioButtonList.SelectedIndex = ItemLoop
    >
    > Exit For
    >
    > End If
    >
    > Next
    >
    >
    >
    > Justin
    >
    >
    >
    >
    >
    > "Hazzard" <hazz@sonic.net> wrote in message
    > news:OtT7vShSDHA.1684@TK2MSFTNGP11.phx.gbl...
    > > Thank you Justin ! Of course, it sets it to a value out of the range of
    > the
    > > valid values.
    > > And what about the comparison of the database value, eg.
    > "radiobuttonvalue1"
    > > ?
    > > Which property do I use to iterate through the list of radiobutton item
    > > values to compare with say, "radiobuttonvalue1?" Is it
    > > radionbuttonlist.items.??? or
    > > radiobutton.items.searchbyvalue("radiobuttonvalue1 ")..
    > >
    > > thank you,
    > > Greg
    > >
    > > "S. Justin Gengo" <gengoj@krause.com> wrote in message
    > > news:vh5cqv4utha44@corp.supernews.com...
    > > > Hazzard,
    > > >
    > > > Have you tried:
    > > >
    > > > RadioButtonList.SelectedIndex = -1
    > > >
    > > > I hope this helps.
    > > >
    > > > Justin
    > > >
    > > >
    > > > "Hazzard" <hazz@sonic.net> wrote in message
    > > > news:uYZa2fgSDHA.1688@TK2MSFTNGP11.phx.gbl...
    > > > > I store radiobuttonlist values in the db using the string value of
    the
    > > > radio
    > > > > button item value. (nvarchar)
    > > > >
    > > > > I am creating an edit functionality on the asp.net form so that when
    I
    > > > reuse
    > > > > my dataentry form for edit, I search the database for the row
    > containing
    > > > the
    > > > > data I want, and then populate all the form fields.
    > > > >
    > > > > here is what I have so far. What I don't know what to do is for
    cases
    > > > where
    > > > > a dirty database has no associated value for the radiobuttonlist, I
    > > don't
    > > > > want to select anything. How do I do that?
    > > > > ***************
    > > > > dbaseReturnValue = arParms(17).Value.ToString() 'get value from
    > > returned
    > > > > stored procedure call.
    > > > > For Each li In RadioButtonList.Items
    > > > > i += 1
    > > > > If (RadioButtonList.Value = dbaseReturnValue Then //but
    > Value
    > > is
    > > > > not a valid member. what do i use?
    > > > > RadioButtonList.SelectedValue = dbaseReturnValue
    > > > > li.Selected = True
    > > > > else
    > > > > RadioButtonList.SelectedValue = ???????????
    > > > > End If
    > > > > Next
    > > > > ***************
    > > > > Thank you,
    > > > > Greg Hazzard
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    Hazzard Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139