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

combo value validation

Hi
I have a web form, using vb.net code behind, with a combo
box populated with a dataset (Name, ID). What I have
found, unlike a windows form, is that if I try to pass a
value (ID) into the combo and that value is not part of
the dataset, the web form blows up.
If (Context.Items("ID") <> "") Then
cboEmployeeID.SelectedValue = Context.Items("ID")
End If
Testing for empty string does help some but there are
times when we have bad data and the ID value will not
match any in the dataset.

Is there a way to trap this so my form does not error out?

Thanks
Brian

Nov 19 '05 #1
4 1734
There are quite a few ways I can think of to start coding this.

1. Try ... Catch

Try
cboEmployeeID.SelectedValue = Context.Items("ID")
Catch
'This is just here to catch the error
End Try

2. Loop through controls collection, looking for this value

Dim cc As ControlsCollection = MyDropDown.Controls

For i = 0 to (cc.Count - 1)
'Loop looking for value
Next

3. Get ControlsCollection and see if it contains a specific key

If (cc.Contains(stringValue)) Then
'Code here to set value
End If

There are probably others. I am most fond of the third value, with some way
of informing the user they typed in something invalid in an Else Condition.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"briandh" wrote:
Hi
I have a web form, using vb.net code behind, with a combo
box populated with a dataset (Name, ID). What I have
found, unlike a windows form, is that if I try to pass a
value (ID) into the combo and that value is not part of
the dataset, the web form blows up.
If (Context.Items("ID") <> "") Then
cboEmployeeID.SelectedValue = Context.Items("ID")
End If
Testing for empty string does help some but there are
times when we have bad data and the ID value will not
match any in the dataset.

Is there a way to trap this so my form does not error out?

Thanks
Brian

Nov 19 '05 #2
try this, it never errors out for bad values

ddUserProg1.SelectedIndex =
ddUserProg1.Items.IndexOf(ddUserProg1.Items.FindBy Value(csUser.ProgramID))

vinay
"briandh" wrote:
Hi
I have a web form, using vb.net code behind, with a combo
box populated with a dataset (Name, ID). What I have
found, unlike a windows form, is that if I try to pass a
value (ID) into the combo and that value is not part of
the dataset, the web form blows up.
If (Context.Items("ID") <> "") Then
cboEmployeeID.SelectedValue = Context.Items("ID")
End If
Testing for empty string does help some but there are
times when we have bad data and the ID value will not
match any in the dataset.

Is there a way to trap this so my form does not error out?

Thanks
Brian

Nov 19 '05 #3
Thank You!
-----Original Message-----
try this, it never errors out for bad values

ddUserProg1.SelectedIndex =
ddUserProg1.Items.IndexOf(ddUserProg1.Items.FindB yValue (csUser.ProgramID))
vinay
"briandh" wrote:
Hi
I have a web form, using vb.net code behind, with a combo box populated with a dataset (Name, ID). What I have
found, unlike a windows form, is that if I try to pass a value (ID) into the combo and that value is not part of the dataset, the web form blows up.
If (Context.Items("ID") <> "") Then
cboEmployeeID.SelectedValue = Context.Items("ID")
End If
Testing for empty string does help some but there are
times when we have bad data and the ID value will not
match any in the dataset.

Is there a way to trap this so my form does not error out?
Thanks
Brian

.

Nov 19 '05 #4

Thank You!

-----Original Message-----
There are quite a few ways I can think of to start coding this.
1. Try ... Catch

Try
cboEmployeeID.SelectedValue = Context.Items("ID")
Catch
'This is just here to catch the error
End Try

2. Loop through controls collection, looking for this value
Dim cc As ControlsCollection = MyDropDown.Controls

For i = 0 to (cc.Count - 1)
'Loop looking for value
Next

3. Get ControlsCollection and see if it contains a specific key
If (cc.Contains(stringValue)) Then
'Code here to set value
End If

There are probably others. I am most fond of the third value, with some wayof informing the user they typed in something invalid in an Else Condition.
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"briandh" wrote:
Hi
I have a web form, using vb.net code behind, with a combo box populated with a dataset (Name, ID). What I have
found, unlike a windows form, is that if I try to pass a value (ID) into the combo and that value is not part of the dataset, the web form blows up.
If (Context.Items("ID") <> "") Then
cboEmployeeID.SelectedValue = Context.Items("ID")
End If
Testing for empty string does help some but there are
times when we have bad data and the ID value will not
match any in the dataset.

Is there a way to trap this so my form does not error out?
Thanks
Brian

.

Nov 19 '05 #5

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

Similar topics

0
by: Joyce | last post by:
The XML Schema design problem to solve is as follows: We have 2 combo boxes to populate from schema data, let's say: 1. States 2. Cities (and this one gets populated depending on the choice of...
11
by: my-wings | last post by:
I think I've painted myself into a corner, and I'm hoping someone can help me out. I have a table of books (tblBooks), which includes a field (strPubName) for Publisher Name and another field...
9
by: Bob Alston | last post by:
I have a drop down combo box that gives the user to enter an item not in the list by adding it to the list. The list is a table. It works fine on Access2003 but fails on Access2002/XP. ON XP, it...
1
by: Brendan | last post by:
I am trying to validate the data in all of the text and combo boxes. The text box validation seems to be working fine, but I am having the hardest time with the combo box validation. I am not sure...
6
by: Michael R. Pierotti | last post by:
Ok now I want to validate / auto select a value from a Combo box, 'cbInterfaceVersion Me.cbInterfaceVersion.Items.AddRange(New Object() {"v 3.3", "v 3.4"}) Me.cbInterfaceVersion.Location = New...
0
by: BrianDH | last post by:
Hi I have a web form, using vb.net code behind, with a combo box populated with a dataset (Name, ID). What I have found, unlike a windows form, is that if you try to pass a value (ID) into the...
0
by: BrianDH | last post by:
Hi I have a web form, using vb.net code behind, with a combo box populated with a dataset (Name, ID). What I have found, unlike a windows form, is that if I try to pass a value (ID) into the...
1
by: bbcdancer | last post by:
Is it possible to restrict the length of a text box in MS Access using VBA on condition to what is selected in a list combo box. Scenario: 1. I have a list combo box containing: AA BBB...
2
by: ddog | last post by:
I have a form with 3 text fields (one of which is a zip code) and 5 combo boxes. The combo boxes are all set with the first value as 'selected' when the page is first displayed. The 3 text fields...
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...
1
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...
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
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.