set selected value on a droplist

Discussion in 'ASP .Net' started by TJS, Mar 9, 2005.

  1. TJS

    TJS Guest

    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.NullReferenceException: 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.FindControl("IDCaptain")
    Line 392: ctrlCaptain.SelectedIndex =
    ctrlCaptain.Items.IndexOf(ctrlCaptain.Items.FindByValue(vCaptainID ))
    TJS, Mar 9, 2005
    #1
    1. Advertising

  2. TJS

    Karl Seguin Guest

    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.FindControl()

    you need to use parentcontrol.FindControl()

    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" <> wrote in message
    news:...
    > 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.NullReferenceException: 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.FindControl("IDCaptain")
    > Line 392: ctrlCaptain.SelectedIndex =
    > ctrlCaptain.Items.IndexOf(ctrlCaptain.Items.FindByValue(vCaptainID ))
    >
    >
    >
    Karl Seguin, Mar 10, 2005
    #2
    1. Advertising

  3. TJS

    TJS Guest

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




    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:...
    > 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.FindControl()
    >
    > you need to use parentcontrol.FindControl()
    >
    > 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" <> wrote in message
    > news:...
    >> 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.NullReferenceException: 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.FindControl("IDCaptain")
    >> Line 392: ctrlCaptain.SelectedIndex =
    >> ctrlCaptain.Items.IndexOf(ctrlCaptain.Items.FindByValue(vCaptainID ))
    >>
    >>
    >>

    >
    >
    TJS, Mar 10, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Meir Rotfleisch

    Newbie Question about DropList and Page Load

    Meir Rotfleisch, Nov 2, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    332
    Thomas F.B.
    Nov 2, 2003
  2. Lasse Edsvik

    Filelist -> Droplist?

    Lasse Edsvik, Oct 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    400
    =?Utf-8?B?c3Jpbmk=?=
    Oct 4, 2004
  3. TJS
    Replies:
    4
    Views:
    2,948
  4. TJS
    Replies:
    5
    Views:
    2,073
    =?Utf-8?B?amZsZWVzb24=?=
    Mar 13, 2005
  5. =?Utf-8?B?Sm9obiBTLg==?=
    Replies:
    0
    Views:
    353
    =?Utf-8?B?Sm9obiBTLg==?=
    Sep 11, 2007
Loading...

Share This Page