在比较值和禁用某些文本框时出错 [英] getting error in comparing values and disabling some text boxes

查看:57
本文介绍了在比较值和禁用某些文本框时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i我试图将文本框值与< =运算符和下拉菜单中接受的值进行比较,如果 textbox1,则为

。值< = 25&& ddl1.SelectedValue!=C
然后在页面上禁用部件。

但数据库中的文本变量声明为varchar。



i我正在尝试这个不能正常工作的代码

请帮助。



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.

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();
            }
        }
            
    }

推荐答案

尝试这样的事情





Try something like this


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


检查代码块内的注释。

Check the comments inside the code block.
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();
            }
        }
    }


这篇关于在比较值和禁用某些文本框时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆