set selected value on a droplist

T

TJS

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 ))
 
K

Karl Seguin

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
 
T

TJS

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top