473,657 Members | 2,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

set selected value on a droplist

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

Nov 19 '05 #1
2 1756
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" <no****@here.co m> wrote in message
news:OT******** ******@TK2MSFTN GP09.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.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 ))

Nov 19 '05 #2
TJS
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:ut******** *****@tk2msftng p13.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.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" <no****@here.co m> wrote in message
news:OT******** ******@TK2MSFTN GP09.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.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 ))


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2430
by: James | last post by:
I was wondering if there is a way to populate a drop down list with the active directory user? So far I have found the namespace System.DirectoryServices but I am not sure how to access the users and attach them to a droplist. Thanks in advace for the help.
1
1765
by: TJS | last post by:
can someone tell me why the selected item won't reflect user change in this little droplist example <%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
1
1381
by: Lasse Edsvik | last post by:
Hello I was wondering if you guys could show me how to fill a droplist with files from a directory? I got this but dont work DirectoryInfo dir = new DirectoryInfo(Server.MapPath("img/")); DropDown1.DataSource = dir.GetFiles(dir);
5
4452
by: Lasse Edsvik | last post by:
Hello I have a dropdown with 3 different values, and it prints out first value no matter how i change it...... private void Button1_Click(object sender, System.EventArgs e) { if(Page.IsValid)
4
1376
by: TJS | last post by:
After a post back the selected index should be rest in a droplist to match user's choice, but page always show selected item as first one in the droplist. How can iforce the selected item to be reset I have: Sub Page_Load(s As Object, e As EventArgs) If Page.IsPostBack then
5
2135
by: TJS | last post by:
I need to add validation to drodownlist control but it sends back an error message that says: "System.Web.UI.WebControls.DropDownList' does not allow child controls" the code is : If e.ItemType = ItemType.FieldItem And e.ColumnName = "IDEvent" Then Dim ctlEvent As DropDownList = CType(e.Control, DropDownList) Dim compVal AS CompareValidator = New CompareValidator()
4
1054
by: TJS | last post by:
I am getting an error message saying HourDropList is not declared What declaration is required ? ......script function to populate droplist..... '******************************************************* Function HourDropDownList(byVal vHour As Integer) '
0
1051
by: =?Utf-8?B?Sm9obiBTLg==?= | last post by:
I programmed a dropdownlist via javascript and now I need to read the value from vb.net code (server side) . Then based on the value I will branch to seperate logic. How do I call a client javascript function from vb.net and return the value to it as well?
4
1717
by: Trish | last post by:
Hello All and thanks in advance for your help. The code below works just fine in the Print event of the report Detail section. Is it possible to condense it using a loop or something? Can you use variables when setting attributes? Thanks again. I learn a lot from reading answers to other people's posts, but haven't seen anything that simplifies this issue. Tricia
0
8385
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8303
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8502
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7316
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.