Tuesday, March 13, 2012

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.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
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.com> wrote in message
news:OThMzkOJFHA.1304@.TK2MSFTNGP09.phx.gbl...
> 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 ))
>
>
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:utY9PtQJFHA.572@.tk2msftngp13.phx.gbl...
> 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" <nospam@.here.com> wrote in message
> news:OThMzkOJFHA.1304@.TK2MSFTNGP09.phx.gbl...
> set
>

0 comments:

Post a Comment