473,326 Members | 2,113 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,326 software developers and data experts.

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_category1.Items.FindByValue(ds.Table s(0).Rows(0)("listingCategory1")).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 6031
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_category1.Items.FindByValue(ds.Table s(0).Rows(0)("listingCategory1")).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_category1.Items.FindByValue(ds.Table s(0).Rows(0)("listingCategory1")).Value.ToString
= "") then...

add

if DropDownList_category1.Items.count > 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**************@TK2MSFTNGP09.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_category1.Items.count > 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
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...
2
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...
1
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...
10
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
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...
2
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...
4
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...
10
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
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.