473,396 Members | 1,689 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.

Simple if statement doesn't work

I have a wizardStep with 2 textBoxes and a button on it. The textBoxes are
called WordTextBox and DefinitionTextBox. In the button_click event, I added
this code:

AddDefinition();

The code for the AddDefinition method is below:

private void AddDefinition() {

///Todo: Add validation for adding duplicate words, empty values

StockContract.Dictionary = new ContractDictionary<string, string>();

if(StockContract.Dictionary.ContainsKey(WordTextBo x.Text)) {

DefinitionList.Caption = "This word already exists!";

return;

}
StockContract.Dictionary.Add(WordTextBox.Text, DefinitionTextBox.Text);

DefinitionList.DataSource = StockContract.Dictionary;

DefinitionList.DataBind();

WordTextBox.Text = String.Empty;

DefinitionTextBox.Text = String.Empty;

}

It creates a Dictionary collection and assigns it to the Dictionary of the
StockContract object. It then takes the 2 textboxes and puts the values
inside the dictionary collection. Everything works fine except the if
statement. It is supposed to determine if the value of WordTextBox.Text is
actualy a Key in the dictionary. If it is already in the collection, change
the caption of the gridview to something different and exit the method
without continuing. If it doesn't already exist, continue adding it to the
collection. Any idea what might be wrong with it?


Jun 27 '08 #1
2 900
What is not working? I assume you've tested with hard coded values, and
stepping through the code in the debugger, etc

Jeff

"Andy B" <a_*****@sbcglobal.netwrote in message
news:OC**************@TK2MSFTNGP02.phx.gbl...
>I have a wizardStep with 2 textBoxes and a button on it. The textBoxes are
called WordTextBox and DefinitionTextBox. In the button_click event, I
added this code:

AddDefinition();

The code for the AddDefinition method is below:

private void AddDefinition() {

///Todo: Add validation for adding duplicate words, empty values

StockContract.Dictionary = new ContractDictionary<string, string>();

if(StockContract.Dictionary.ContainsKey(WordTextBo x.Text)) {

DefinitionList.Caption = "This word already exists!";

return;

}
StockContract.Dictionary.Add(WordTextBox.Text, DefinitionTextBox.Text);

DefinitionList.DataSource = StockContract.Dictionary;

DefinitionList.DataBind();

WordTextBox.Text = String.Empty;

DefinitionTextBox.Text = String.Empty;

}

It creates a Dictionary collection and assigns it to the Dictionary of the
StockContract object. It then takes the 2 textboxes and puts the values
inside the dictionary collection. Everything works fine except the if
statement. It is supposed to determine if the value of WordTextBox.Text is
actualy a Key in the dictionary. If it is already in the collection,
change the caption of the gridview to something different and exit the
method without continuing. If it doesn't already exist, continue adding it
to the collection. Any idea what might be wrong with it?


Jun 27 '08 #2
You may not be showing us everything, but it doesn't look like you're
looking for case sensitivity in here. I would insert all values
as .ToUpper or .ToLower and check the textbox.text.tolower[toUpper]
against the dictionary. You'll also want to .Trim the text.
Jun 27 '08 #3

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

Similar topics

0
by: Alex Glaros | last post by:
I need help on my basic table connection syntaxt using PHP. I call the php from a web browser url_name_goes_here/test.php. The database name is tennis and the user name is tennis. If I type...
27
by: Brian Sabbey | last post by:
Here is a first draft of a PEP for thunks. Please let me know what you think. If there is a positive response, I will create a real PEP. I made a patch that implements thunks as described here....
6
by: Arthur J. O'Dwyer | last post by:
I was paging through Coplien's book "Advanced C++ Programming Styles and Idioms" this afternoon and found some code that looked something like void sort(vector<foo> a) { int flip; do { for...
6
by: Pete | last post by:
Hello everybody -- Forgive my multi-posting my question. I posted first to ciwah, but I learned that ciwas is the better group for this CSS question. The problem has me stopped. The page: ...
7
by: NS Develop | last post by:
What's wrong with the following: void SomeClass::someMethod(void) { A *ptrA = NULL; ptrA = &A(); .... }
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
33
by: hermit_crab67 | last post by:
Can someone explain to a C newbie why this doesn't work as I expect it to work? (expectations clearly outlined in the printf statement in main routine) OS: Linux 2.4.26 GCC: 2.95.4 void...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
13
by: John Dann | last post by:
A Python newbie, but some basic understanding of how classes, objects etc work in eg VB.Net. However, I'm struggling a little to translate this knowledge into the Python context. I'm trying to...
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
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.