Click here to Skip to main content
15,905,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ,
i am trying to compare a textbox value with <= operator and value accepted in a drop down like
if textbox1.value <=25 && ddl1.SelectedValue != "C" then disable a part on page.
but text variable in database is declared as varchar.

i am trying this code which is not working
please Help.

C#
protected void txtContractorBusinesscapacity_TextChanged(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(txtContractorBusinesscapacity.Text))
        {
            int value = 0;

            bool isParsed = int.TryParse(txtContractorBusinesscapacity.Text, out value);

            if (isParsed && value <= 25 && ddlContractorTypeID.SelectedValue != "C")
      
            {

                DisableConsumerPart();

            }
            else
            {
                EnableConsumerPart();
            }
        }
            
    }
Posted
Updated 7-Jan-14 0:07am
v2
Comments
OriginalGriff 7-Jan-14 6:15am    
"is not working" is not a helpful error message.
Does it compile? Run? Is there an error message of some form? What does it do that you didn't expect, or not do that you did? Does the textbox value parse ok?
ruby kaur 7-Jan-14 6:20am    
code is not giving any error in compilation but when i give value <25 in the text box its not disabling that part of the page.

Try something like this


C#
if ((isParsed) && (value <= 25) && (ddlContractorTypeID.SelectedValue != "C"))
 
Share this answer
 
Comments
ruby kaur 7-Jan-14 6:23am    
this also not work.
ravikhoda 7-Jan-14 6:29am    
Code looks okay...Try and debug things by adding a break point and check values of each variables. it may help you ? or check the ddlContractorTypeID.SelectedValue in the quick watch.

see if isParsed=true
Check the comments inside the code block.
C#
protected void txtContractorBusinesscapacity_TextChanged(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(txtContractorBusinesscapacity.Text))
        {
            int value = 0;

            bool isParsed = int.TryParse(txtContractorBusinesscapacity.Text, out value);

            // Put a break point here. Check what are the values of isParsed, value and ddlContractorTypeID.SelectedValue by hovering mouse on them. Are they satisfying the "if" condition?
            if (isParsed && value <= 25 && ddlContractorTypeID.SelectedValue != "C")
            {
                DisableConsumerPart();
            }
            else
            {
                EnableConsumerPart();
            }
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900