473,651 Members | 2,835 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

checking to see if DDL value exists

I'm trying to add an extra layer of error checking on a Drop Down List. The
list is populated from one table, and then I select the selectedValue from
another DB.

While it SHOULDN'T ever happen, just incase, I want to check that the
selected value actually exists as a value in the dropDownList before I
actually try to select it.

I've tried this:

if
(DropDownList_c ategory1.Items. FindByValue(ds. Tables(0).Rows( 0)("listingCate gory1")).Value. ToString
= "") then...

But that just gives me a " Object reference not set to an instance of an
object. " error.

-Darrel

Nov 19 '05 #1
4 6049
What you would probably want to do is do the checking against the
dataset before you actually do the binding. Even if the selected value
doesn't exist, I'm not sure that anything will happen other than nothing
will be selected. You could easily test this by manually setting the
selectedvalue to something that you know does not exist.

Lowell


Darrel wrote:
I'm trying to add an extra layer of error checking on a Drop Down List. The
list is populated from one table, and then I select the selectedValue from
another DB.

While it SHOULDN'T ever happen, just incase, I want to check that the
selected value actually exists as a value in the dropDownList before I
actually try to select it.

I've tried this:

if
(DropDownList_c ategory1.Items. FindByValue(ds. Tables(0).Rows( 0)("listingCate gory1")).Value. ToString
= "") then...

But that just gives me a " Object reference not set to an instance of an
object. " error.

-Darrel

Nov 19 '05 #2
> What you would probably want to do is do the checking against the dataset
before you actually do the binding. Even if the selected value doesn't
exist, I'm not sure that anything will happen other than nothing will be
selected. You could easily test this by manually setting the selectedvalue
to something that you know does not exist.


Well, the catch is if the item doesn't exist, I actually want it to select a
differerent item.

As for checking in the dataset, I'm still not quite sure how to go about
that. I could grab the list of categories from table1 and put it in an
array, then, when I grab the record from table2, I could compare the
pertinent field with that array. I'm trying to come up with a simpler
solution though.

Let me sleep on it ;o)

-Darrel
Nov 19 '05 #3
Hi,

before this code

if
(DropDownList_c ategory1.Items. FindByValue(ds. Tables(0).Rows( 0)("listingCate gory1")).Value. ToString
= "") then...

add

if DropDownList_ca tegory1.Items.c ount > 0 then

remember to add the "End If" tag if you are in VB.NET

hope it helps

weichung

hope
"Darrel" <no*****@nospam .com> wrote in message
news:uT******** ******@TK2MSFTN GP09.phx.gbl...
What you would probably want to do is do the checking against the dataset
before you actually do the binding. Even if the selected value doesn't
exist, I'm not sure that anything will happen other than nothing will be
selected. You could easily test this by manually setting the
selectedvalue to something that you know does not exist.


Well, the catch is if the item doesn't exist, I actually want it to select
a differerent item.

As for checking in the dataset, I'm still not quite sure how to go about
that. I could grab the list of categories from table1 and put it in an
array, then, when I grab the record from table2, I could compare the
pertinent field with that array. I'm trying to come up with a simpler
solution though.

Let me sleep on it ;o)

-Darrel

Nov 19 '05 #4
> add

if DropDownList_ca tegory1.Items.c ount > 0 then

remember to add the "End If" tag if you are in VB.NET

I don't think I'm quite explaining this correctly. Let's say my DDL has the
following value options:

3
4
5
8
9
12
0

These would be all the active options pulled from Table 1.

Then, in table 2, I grab the data for a specific record, who's foreign key
for Table 1 is '2'.

Since 2 doesn't exist as an option in the DDL, I can't select it. So,
instead, I want to select '0'.

However, all this said, I'm thinking there really should be no reason to do
this error checking here. I really need to spot the problem prior to this
step. That said, I am curious if there is a simple way to see if a DDL.item
exists.

-Darrel
Nov 19 '05 #5

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

Similar topics

1
7758
by: Keiron Waites | last post by:
I'd like to do something like this, where the script checks to see if an option exists: if (document.formname.selectname.options) != NULL) { do something; } So it would return true if <option value="optionvalue"></option> existed. Any ideas?
2
10049
by: dixie | last post by:
I am trying to write some VBA that can check if a certain value exists in a field in a table. The field is a text field. The table is not a part of the query that forms the recordsource of the form on which I am trying to do this. I wish to act on the presence (or absence) of this value. What I am doing is trying to have a generic password form such that when you click a button to open the next form, the code checks if there is a letter...
1
1095
by: Stu | last post by:
Hi, I have a web form that uses simple binding to bind properties to the controls on the page. However, if I try and bind a value to a dd list using: SelectedValue="<%# MyProperty %>" If the value doesn't exist it throws and error: Object reference not set to an instance of an object. Is there any way to test if a value exists in a DD list (preferably without
10
1403
by: codefire | last post by:
Hi, I have some simple code - which works...kind of..here's the code: import os def print_tree(start_dir): for f in os.listdir(start_dir): fp = os.path.join(start_dir, f)
5
27429
by: =?Utf-8?B?QnJlbmRlbiBCaXhsZXI=?= | last post by:
Hello. I am reading a value from a table and trying to determine if that value exists in a list of values associated with a dropdownlist. If so, I select the value, otherwise, I don't. I haven't been able to figure this operation out so far. Code: if (reader != System.DBNull.Value)
2
2101
by: causesdrowsiness | last post by:
Hi everyone. Sorry if this is the wrong group for this question, but since it is .NET and VB, I thought someone may be able to help me here or point me to the right group for this. I am working on an application which needs to check if a certain VALUE exists in a registry subkey. Is there an easy way to do this? So far, my googles have come up empty on this, though they DO have a plethora of information on checking if a KEY exists.
4
4360
Curben
by: Curben | last post by:
I have a form in my DB based on an updateable lookup query. When the form closes a macro runs removing all the records and updating them into a table bases an a yes/no control on the form. If the control is checked it will be added in a way that the next user will see it on their forms and queries. If the control is not checked the record is added in a way that it will not show up in other queries except on a report just to show it was reviewed....
10
41161
by: Dooza | last post by:
Using ASP with VBScript is there a clever way to easily check if a value exists in an array without looping through it? Steve
2
14650
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how can I pass null value as parameter to the database stored procedure programattically using C#? Although I can check for empty column (the following code passes string.Empty as parameter but how to pass null value?), I cannot check for null value...
0
8277
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
8465
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
8581
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7298
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
6158
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
5612
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
4285
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
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
1
1910
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.