473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.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.FindBy Value(vCaptainID ))

Nov 19 '05 #1
2 1736
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" <no****@here.com> wrote in message
news:OT**************@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.FindBy Value(vCaptainID ))

Nov 19 '05 #2
TJS
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:ut*************@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" <no****@here.com> wrote in message
news:OT**************@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.FindBy Value(vCaptainID ))


Nov 19 '05 #3

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

Similar topics

1
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...
1
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,...
1
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/")); ...
5
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) { ...
4
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...
5
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...
4
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..... ...
0
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...

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.