set selected value on a droplist

  • Thread starter Thread starter TJS
  • Start date Start date
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 ))
 
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
 
the eventform is the parentcontrol, but I was able to produce the desired
effect using "OnItemCreated "
 
Back
Top