set selected value on a droplist

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

    set selected value on a droplist

    need help with trying to set selected value on a droplist.
    -- tried vCaptainID as integer and string , no luck
    -- tried it in pre render and also after droplist is created , no luck

    ========= error =============== =======
    Exception Details: System.NullRefe renceException: Object reference not set
    to an instance of an object.

    Source Error line 392 :

    Line 390: vCaptainID =5 '<=test value which exists in droplist
    Line 391: Dim ctrlCaptain as DropDownList =
    Eventform.FindC ontrol("IDCapta in")
    Line 392: ctrlCaptain.Sel ectedIndex =
    ctrlCaptain.Ite ms.IndexOf(ctrl Captain.Items.F indByValue(vCap tainID ))



  • Karl Seguin

    #2
    Re: set selected value on a droplist

    My guess is that the FindControl isn't finding "IDCaptain" and ctrlCaptain
    is null...

    if IDCaptain is embedded inside another control it won't be found via
    Page.FindContro l()

    you need to use parentcontrol.F indControl()

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)


    "TJS" <nospam@here.co m> wrote in message
    news:OThMzkOJFH A.1304@TK2MSFTN GP09.phx.gbl...[color=blue]
    > need help with trying to set selected value on a droplist.
    > -- tried vCaptainID as integer and string , no luck
    > -- tried it in pre render and also after droplist is created , no luck
    >
    > ========= error =============== =======
    > Exception Details: System.NullRefe renceException: Object reference not[/color]
    set[color=blue]
    > to an instance of an object.
    >
    > Source Error line 392 :
    >
    > Line 390: vCaptainID =5 '<=test value which exists in droplist
    > Line 391: Dim ctrlCaptain as DropDownList =
    > Eventform.FindC ontrol("IDCapta in")
    > Line 392: ctrlCaptain.Sel ectedIndex =
    > ctrlCaptain.Ite ms.IndexOf(ctrl Captain.Items.F indByValue(vCap tainID ))
    >
    >
    >[/color]


    Comment

    • TJS

      #3
      Re: set selected value on a droplist

      the eventform is the parentcontrol, but I was able to produce the desired
      effect using "OnItemCrea ted "




      "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
      wrote in message news:utY9PtQJFH A.572@tk2msftng p13.phx.gbl...[color=blue]
      > My guess is that the FindControl isn't finding "IDCaptain" and ctrlCaptain
      > is null...
      >
      > if IDCaptain is embedded inside another control it won't be found via
      > Page.FindContro l()
      >
      > you need to use parentcontrol.F indControl()
      >
      > Karl
      >
      > --
      > MY ASP.Net tutorials
      > http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
      > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
      > come!)
      >
      >
      > "TJS" <nospam@here.co m> wrote in message
      > news:OThMzkOJFH A.1304@TK2MSFTN GP09.phx.gbl...[color=green]
      >> need help with trying to set selected value on a droplist.
      >> -- tried vCaptainID as integer and string , no luck
      >> -- tried it in pre render and also after droplist is created , no luck
      >>
      >> ========= error =============== =======
      >> Exception Details: System.NullRefe renceException: Object reference not[/color]
      > set[color=green]
      >> to an instance of an object.
      >>
      >> Source Error line 392 :
      >>
      >> Line 390: vCaptainID =5 '<=test value which exists in droplist
      >> Line 391: Dim ctrlCaptain as DropDownList =
      >> Eventform.FindC ontrol("IDCapta in")
      >> Line 392: ctrlCaptain.Sel ectedIndex =
      >> ctrlCaptain.Ite ms.IndexOf(ctrl Captain.Items.F indByValue(vCap tainID ))
      >>
      >>
      >>[/color]
      >
      >[/color]


      Comment

      Working...