Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Simple if statement doesn't work

Reply
Thread Tools

Simple if statement doesn't work

 
 
Andy B
Guest
Posts: n/a
 
      04-25-2008
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?






 
Reply With Quote
 
 
 
 
Jeff Dillon
Guest
Posts: n/a
 
      04-25-2008
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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?
>
>
>
>
>
>



 
Reply With Quote
 
 
 
 
cfps.Christian
Guest
Posts: n/a
 
      04-25-2008
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if statement that, when false, skips first statement in its block, executes second? Jay McGavren Java 11 01-16-2006 05:49 PM
How do I do a conditional statement in a constant statement? tkvhdl@gmail.com VHDL 3 12-16-2005 06:13 PM
Simple comparison statement that doesn't work ranrodrig Perl Misc 2 12-15-2005 03:40 AM
exec "statement" VS. exec "statement in globals(), locals() Ted Python 1 07-22-2004 08:51 AM
exec "statement" VS. exec "statement" in globals(), locals() tedsuzman Python 2 07-21-2004 08:41 PM



Advertisments