如何解决这个错误 [英] how to resolve thisr error

查看:90
本文介绍了如何解决这个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法将参数值从字符串转换为布尔值.这是错误消息

Failed to convert parameter value from a String to a Boolean. this is error message

推荐答案

作为消息提示,当您尝试将字符串转换为布尔类型时会发生此错误.

调试并逐步执行代码.找到发生此错误的行,然后尝试找出执行转换的原因. 您可以使用Boolean.TryParse 方法 [
As the message suggets, this error occurs when you try and convert a string to a boolean type.

Debug and step through your code. Find the line where this error occurs and try and figure out why you are doing the conversion.
You can use the Boolean.TryParse method[^] to avoid this error.



bool xxx = bool.TryParse("false", out xxx);
        //return if true or false if succeeded return true and if faild return false
        if (xxx == true)
        {
            bool y = Convert.ToBoolean(xxx);
            Response.Write("<script>alert('"+xxx.ToString() +"')</script>");
        }
        else
        {
            Response.Write("<script>alert('Failed')</script>");
        }


最好的问候
米特瓦里(M.Mitwalli)


Best Regards
M.Mitwalli


这篇关于如何解决这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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