populating radiobuttonlist from database programmatically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hazzard

    #1

    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?
    ***************
    dbaseReturnValu e = arParms(17).Val ue.ToString() 'get value from returned
    stored procedure call.
    For Each li In RadioButtonList .Items
    i += 1
    If (RadioButtonLis t.Value = dbaseReturnValu e Then //but Value is
    not a valid member. what do i use?
    RadioButtonList .SelectedValue = dbaseReturnValu e
    li.Selected = True
    else
    RadioButtonList .SelectedValue = ???????????
    End If
    Next
    ***************
    Thank you,
    Greg Hazzard


  • Hazzard

    #2
    Re: populating radiobuttonlist from database programmaticall y

    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. "radiobuttonval ue1"
    ?
    Which property do I use to iterate through the list of radiobutton item
    values to compare with say, "radiobuttonval ue1?" Is it
    radionbuttonlis t.items.??? or
    radiobutton.ite ms.searchbyvalu e("radiobuttonv alue1")..

    thank you,
    Greg

    "S. Justin Gengo" <gengoj@krause. com> wrote in message
    news:vh5cqv4uth a44@corp.supern ews.com...[color=blue]
    > Hazzard,
    >
    > Have you tried:
    >
    > RadioButtonList .SelectedIndex = -1
    >
    > I hope this helps.
    >
    > Justin
    >
    >
    > "Hazzard" <hazz@sonic.net > wrote in message
    > news:uYZa2fgSDH A.1688@TK2MSFTN GP11.phx.gbl...[color=green]
    > > I store radiobuttonlist values in the db using the string value of the[/color]
    > radio[color=green]
    > > button item value. (nvarchar)
    > >
    > > I am creating an edit functionality on the asp.net form so that when I[/color]
    > reuse[color=green]
    > > my dataentry form for edit, I search the database for the row containing[/color]
    > the[color=green]
    > > 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[/color]
    > where[color=green]
    > > a dirty database has no associated value for the radiobuttonlist , I[/color][/color]
    don't[color=blue][color=green]
    > > want to select anything. How do I do that?
    > > ***************
    > > dbaseReturnValu e = arParms(17).Val ue.ToString() 'get value from[/color][/color]
    returned[color=blue][color=green]
    > > stored procedure call.
    > > For Each li In RadioButtonList .Items
    > > i += 1
    > > If (RadioButtonLis t.Value = dbaseReturnValu e Then //but Value[/color][/color]
    is[color=blue][color=green]
    > > not a valid member. what do i use?
    > > RadioButtonList .SelectedValue = dbaseReturnValu e
    > > li.Selected = True
    > > else
    > > RadioButtonList .SelectedValue = ???????????
    > > End If
    > > Next
    > > ***************
    > > Thank you,
    > > Greg Hazzard
    > >
    > >[/color]
    >
    >[/color]


    Comment

    • Hazzard

      #3
      Re: populating radiobuttonlist from database programmaticall y

      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. "radiobuttonval ue1"
      ?
      Which property do I use to iterate through the list of radiobutton item
      values to compare with say, "radiobuttonval ue1?" Is it
      radionbuttonlis t.items.??? or
      radiobutton.ite ms.searchbyvalu e("radiobuttonv alue1")..

      thank you,
      Greg

      "S. Justin Gengo" <gengoj@krause. com> wrote in message
      news:vh5cqv4uth a44@corp.supern ews.com...[color=blue]
      > Hazzard,
      >
      > Have you tried:
      >
      > RadioButtonList .SelectedIndex = -1
      >
      > I hope this helps.
      >
      > Justin
      >
      >
      > "Hazzard" <hazz@sonic.net > wrote in message
      > news:uYZa2fgSDH A.1688@TK2MSFTN GP11.phx.gbl...[color=green]
      > > I store radiobuttonlist values in the db using the string value of the[/color]
      > radio[color=green]
      > > button item value. (nvarchar)
      > >
      > > I am creating an edit functionality on the asp.net form so that when I[/color]
      > reuse[color=green]
      > > my dataentry form for edit, I search the database for the row containing[/color]
      > the[color=green]
      > > 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[/color]
      > where[color=green]
      > > a dirty database has no associated value for the radiobuttonlist , I[/color][/color]
      don't[color=blue][color=green]
      > > want to select anything. How do I do that?
      > > ***************
      > > dbaseReturnValu e = arParms(17).Val ue.ToString() 'get value from[/color][/color]
      returned[color=blue][color=green]
      > > stored procedure call.
      > > For Each li In RadioButtonList .Items
      > > i += 1
      > > If (RadioButtonLis t.Value = dbaseReturnValu e Then //but Value[/color][/color]
      is[color=blue][color=green]
      > > not a valid member. what do i use?
      > > RadioButtonList .SelectedValue = dbaseReturnValu e
      > > li.Selected = True
      > > else
      > > RadioButtonList .SelectedValue = ???????????
      > > End If
      > > Next
      > > ***************
      > > Thank you,
      > > Greg Hazzard
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • S. Justin Gengo

        #4
        Re: populating radiobuttonlist from database programmaticall y

        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 = dbaseReturnValu e Then

        RadioButtonList .SelectedIndex = ItemLoop

        Exit For

        End If

        Next



        Justin





        "Hazzard" <hazz@sonic.net > wrote in message
        news:OtT7vShSDH A.1684@TK2MSFTN GP11.phx.gbl...[color=blue]
        > Thank you Justin ! Of course, it sets it to a value out of the range of[/color]
        the[color=blue]
        > valid values.
        > And what about the comparison of the database value, eg.[/color]
        "radiobuttonval ue1"[color=blue]
        > ?
        > Which property do I use to iterate through the list of radiobutton item
        > values to compare with say, "radiobuttonval ue1?" Is it
        > radionbuttonlis t.items.??? or
        > radiobutton.ite ms.searchbyvalu e("radiobuttonv alue1")..
        >
        > thank you,
        > Greg
        >
        > "S. Justin Gengo" <gengoj@krause. com> wrote in message
        > news:vh5cqv4uth a44@corp.supern ews.com...[color=green]
        > > Hazzard,
        > >
        > > Have you tried:
        > >
        > > RadioButtonList .SelectedIndex = -1
        > >
        > > I hope this helps.
        > >
        > > Justin
        > >
        > >
        > > "Hazzard" <hazz@sonic.net > wrote in message
        > > news:uYZa2fgSDH A.1688@TK2MSFTN GP11.phx.gbl...[color=darkred]
        > > > I store radiobuttonlist values in the db using the string value of the[/color]
        > > radio[color=darkred]
        > > > button item value. (nvarchar)
        > > >
        > > > I am creating an edit functionality on the asp.net form so that when I[/color]
        > > reuse[color=darkred]
        > > > my dataentry form for edit, I search the database for the row[/color][/color][/color]
        containing[color=blue][color=green]
        > > the[color=darkred]
        > > > 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[/color]
        > > where[color=darkred]
        > > > a dirty database has no associated value for the radiobuttonlist , I[/color][/color]
        > don't[color=green][color=darkred]
        > > > want to select anything. How do I do that?
        > > > ***************
        > > > dbaseReturnValu e = arParms(17).Val ue.ToString() 'get value from[/color][/color]
        > returned[color=green][color=darkred]
        > > > stored procedure call.
        > > > For Each li In RadioButtonList .Items
        > > > i += 1
        > > > If (RadioButtonLis t.Value = dbaseReturnValu e Then //but[/color][/color][/color]
        Value[color=blue]
        > is[color=green][color=darkred]
        > > > not a valid member. what do i use?
        > > > RadioButtonList .SelectedValue = dbaseReturnValu e
        > > > li.Selected = True
        > > > else
        > > > RadioButtonList .SelectedValue = ???????????
        > > > End If
        > > > Next
        > > > ***************
        > > > Thank you,
        > > > Greg Hazzard
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • S. Justin Gengo

          #5
          Re: populating radiobuttonlist from database programmaticall y

          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 = dbaseReturnValu e Then

          RadioButtonList .SelectedIndex = ItemLoop

          Exit For

          End If

          Next



          Justin





          "Hazzard" <hazz@sonic.net > wrote in message
          news:OtT7vShSDH A.1684@TK2MSFTN GP11.phx.gbl...[color=blue]
          > Thank you Justin ! Of course, it sets it to a value out of the range of[/color]
          the[color=blue]
          > valid values.
          > And what about the comparison of the database value, eg.[/color]
          "radiobuttonval ue1"[color=blue]
          > ?
          > Which property do I use to iterate through the list of radiobutton item
          > values to compare with say, "radiobuttonval ue1?" Is it
          > radionbuttonlis t.items.??? or
          > radiobutton.ite ms.searchbyvalu e("radiobuttonv alue1")..
          >
          > thank you,
          > Greg
          >
          > "S. Justin Gengo" <gengoj@krause. com> wrote in message
          > news:vh5cqv4uth a44@corp.supern ews.com...[color=green]
          > > Hazzard,
          > >
          > > Have you tried:
          > >
          > > RadioButtonList .SelectedIndex = -1
          > >
          > > I hope this helps.
          > >
          > > Justin
          > >
          > >
          > > "Hazzard" <hazz@sonic.net > wrote in message
          > > news:uYZa2fgSDH A.1688@TK2MSFTN GP11.phx.gbl...[color=darkred]
          > > > I store radiobuttonlist values in the db using the string value of the[/color]
          > > radio[color=darkred]
          > > > button item value. (nvarchar)
          > > >
          > > > I am creating an edit functionality on the asp.net form so that when I[/color]
          > > reuse[color=darkred]
          > > > my dataentry form for edit, I search the database for the row[/color][/color][/color]
          containing[color=blue][color=green]
          > > the[color=darkred]
          > > > 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[/color]
          > > where[color=darkred]
          > > > a dirty database has no associated value for the radiobuttonlist , I[/color][/color]
          > don't[color=green][color=darkred]
          > > > want to select anything. How do I do that?
          > > > ***************
          > > > dbaseReturnValu e = arParms(17).Val ue.ToString() 'get value from[/color][/color]
          > returned[color=green][color=darkred]
          > > > stored procedure call.
          > > > For Each li In RadioButtonList .Items
          > > > i += 1
          > > > If (RadioButtonLis t.Value = dbaseReturnValu e Then //but[/color][/color][/color]
          Value[color=blue]
          > is[color=green][color=darkred]
          > > > not a valid member. what do i use?
          > > > RadioButtonList .SelectedValue = dbaseReturnValu e
          > > > li.Selected = True
          > > > else
          > > > RadioButtonList .SelectedValue = ???????????
          > > > End If
          > > > Next
          > > > ***************
          > > > Thank you,
          > > > Greg Hazzard
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Hazzard

            #6
            Re: populating radiobuttonlist from database programmaticall y

            Thank you Justin! It even floats over a dirty database. Clean algorithm.
            _greg
            *************** *************** ******
            arReturnParms(x ) = arParms(x).Valu e.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:vh5hh645oj c86e@corp.super news.com...[color=blue]
            > 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 = dbaseReturnValu e Then
            >
            > RadioButtonList .SelectedIndex = ItemLoop
            >
            > Exit For
            >
            > End If
            >
            > Next
            >
            >
            >
            > Justin
            >
            >
            >
            >
            >
            > "Hazzard" <hazz@sonic.net > wrote in message
            > news:OtT7vShSDH A.1684@TK2MSFTN GP11.phx.gbl...[color=green]
            > > Thank you Justin ! Of course, it sets it to a value out of the range of[/color]
            > the[color=green]
            > > valid values.
            > > And what about the comparison of the database value, eg.[/color]
            > "radiobuttonval ue1"[color=green]
            > > ?
            > > Which property do I use to iterate through the list of radiobutton item
            > > values to compare with say, "radiobuttonval ue1?" Is it
            > > radionbuttonlis t.items.??? or
            > > radiobutton.ite ms.searchbyvalu e("radiobuttonv alue1")..
            > >
            > > thank you,
            > > Greg
            > >
            > > "S. Justin Gengo" <gengoj@krause. com> wrote in message
            > > news:vh5cqv4uth a44@corp.supern ews.com...[color=darkred]
            > > > Hazzard,
            > > >
            > > > Have you tried:
            > > >
            > > > RadioButtonList .SelectedIndex = -1
            > > >
            > > > I hope this helps.
            > > >
            > > > Justin
            > > >
            > > >
            > > > "Hazzard" <hazz@sonic.net > wrote in message
            > > > news:uYZa2fgSDH A.1688@TK2MSFTN GP11.phx.gbl...
            > > > > I store radiobuttonlist values in the db using the string value of[/color][/color][/color]
            the[color=blue][color=green][color=darkred]
            > > > radio
            > > > > button item value. (nvarchar)
            > > > >
            > > > > I am creating an edit functionality on the asp.net form so that when[/color][/color][/color]
            I[color=blue][color=green][color=darkred]
            > > > reuse
            > > > > my dataentry form for edit, I search the database for the row[/color][/color]
            > containing[color=green][color=darkred]
            > > > 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[/color][/color][/color]
            cases[color=blue][color=green][color=darkred]
            > > > where
            > > > > a dirty database has no associated value for the radiobuttonlist , I[/color]
            > > don't[color=darkred]
            > > > > want to select anything. How do I do that?
            > > > > ***************
            > > > > dbaseReturnValu e = arParms(17).Val ue.ToString() 'get value from[/color]
            > > returned[color=darkred]
            > > > > stored procedure call.
            > > > > For Each li In RadioButtonList .Items
            > > > > i += 1
            > > > > If (RadioButtonLis t.Value = dbaseReturnValu e Then //but[/color][/color]
            > Value[color=green]
            > > is[color=darkred]
            > > > > not a valid member. what do i use?
            > > > > RadioButtonList .SelectedValue = dbaseReturnValu e
            > > > > li.Selected = True
            > > > > else
            > > > > RadioButtonList .SelectedValue = ???????????
            > > > > End If
            > > > > Next
            > > > > ***************
            > > > > Thank you,
            > > > > Greg Hazzard
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Hazzard

              #7
              Re: populating radiobuttonlist from database programmaticall y

              Thank you Justin! It even floats over a dirty database. Clean algorithm.
              _greg
              *************** *************** ******
              arReturnParms(x ) = arParms(x).Valu e.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:vh5hh645oj c86e@corp.super news.com...[color=blue]
              > 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 = dbaseReturnValu e Then
              >
              > RadioButtonList .SelectedIndex = ItemLoop
              >
              > Exit For
              >
              > End If
              >
              > Next
              >
              >
              >
              > Justin
              >
              >
              >
              >
              >
              > "Hazzard" <hazz@sonic.net > wrote in message
              > news:OtT7vShSDH A.1684@TK2MSFTN GP11.phx.gbl...[color=green]
              > > Thank you Justin ! Of course, it sets it to a value out of the range of[/color]
              > the[color=green]
              > > valid values.
              > > And what about the comparison of the database value, eg.[/color]
              > "radiobuttonval ue1"[color=green]
              > > ?
              > > Which property do I use to iterate through the list of radiobutton item
              > > values to compare with say, "radiobuttonval ue1?" Is it
              > > radionbuttonlis t.items.??? or
              > > radiobutton.ite ms.searchbyvalu e("radiobuttonv alue1")..
              > >
              > > thank you,
              > > Greg
              > >
              > > "S. Justin Gengo" <gengoj@krause. com> wrote in message
              > > news:vh5cqv4uth a44@corp.supern ews.com...[color=darkred]
              > > > Hazzard,
              > > >
              > > > Have you tried:
              > > >
              > > > RadioButtonList .SelectedIndex = -1
              > > >
              > > > I hope this helps.
              > > >
              > > > Justin
              > > >
              > > >
              > > > "Hazzard" <hazz@sonic.net > wrote in message
              > > > news:uYZa2fgSDH A.1688@TK2MSFTN GP11.phx.gbl...
              > > > > I store radiobuttonlist values in the db using the string value of[/color][/color][/color]
              the[color=blue][color=green][color=darkred]
              > > > radio
              > > > > button item value. (nvarchar)
              > > > >
              > > > > I am creating an edit functionality on the asp.net form so that when[/color][/color][/color]
              I[color=blue][color=green][color=darkred]
              > > > reuse
              > > > > my dataentry form for edit, I search the database for the row[/color][/color]
              > containing[color=green][color=darkred]
              > > > 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[/color][/color][/color]
              cases[color=blue][color=green][color=darkred]
              > > > where
              > > > > a dirty database has no associated value for the radiobuttonlist , I[/color]
              > > don't[color=darkred]
              > > > > want to select anything. How do I do that?
              > > > > ***************
              > > > > dbaseReturnValu e = arParms(17).Val ue.ToString() 'get value from[/color]
              > > returned[color=darkred]
              > > > > stored procedure call.
              > > > > For Each li In RadioButtonList .Items
              > > > > i += 1
              > > > > If (RadioButtonLis t.Value = dbaseReturnValu e Then //but[/color][/color]
              > Value[color=green]
              > > is[color=darkred]
              > > > > not a valid member. what do i use?
              > > > > RadioButtonList .SelectedValue = dbaseReturnValu e
              > > > > li.Selected = True
              > > > > else
              > > > > RadioButtonList .SelectedValue = ???????????
              > > > > End If
              > > > > Next
              > > > > ***************
              > > > > Thank you,
              > > > > Greg Hazzard
              > > > >
              > > > >
              > > >
              > > >[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              Working...