无法将字符串识别为有效的布尔值

无法将字符串识别为有效的布尔值

本文介绍了无法将字符串识别为有效的布尔值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.. !!

早安.. !!

我的代码在这里,代码中有错误字符串未被识别为有效的布尔值".以粗线显示

任何人都可以帮助我.



Hello..!!

Good Morning..!!

My code is here there is Error in Code "String was not recognized as a valid Boolean." which displayed in bold line

anybody Help me what can i do for it.



protected void Page_Load(object sender, EventArgs e)
   {
       lblReqMsg.Text = GlobleVariable.strReqMsg;
       ltrheading.Text = "Add Gallery";
       Title = "Add Gallery" + ConfigurationManager.AppSettings["AdminTitle"];
       if (Page.IsPostBack == false) {
       if (!string.IsNullOrEmpty(Request["Id"]))
       {
           int res;
           if (int.TryParse(Request["Id"],out res))
           {
               if (Request["Flag"] == "Edit") {
                   Title = "Edit Gallery" + ConfigurationManager.AppSettings["AdminTitle"];
                   ltrheading.Text = "Edit Gallery";
                   DataSet dssubcat = new DataSet();
                   objgallery.id = Convert.ToInt32(Request["id"]);
                   dssubcat = objgallery.SelectSingleItem();
                   if (dssubcat.Tables[0].Rows.Count > 0) {
                       txtTitle.Text = (string)dssubcat.Tables[0].Rows[0]["gallery_name"];
                       chkactive.Checked = Convert.ToBoolean(dssubcat.Tables[0].Rows[0]["activestatus"]);
                       if (Convert.ToBoolean((dssubcat.Tables[0].Rows[0]["gallery_img"]) == System.DBNull.Value ? "" : dssubcat.Tables[0].Rows[0]["gallery_img"]))
                       {
                           ViewState["gallery_img"] = "";
                           lblimgmsg.Visible = true;
                       }
                       else {
                           ViewState["gallery_img"] = ((string)dssubcat.Tables[0].Rows[0]["gallery_img"]).Replace("''", "'");
                           aimg.Visible = true;
                           //lblseperator.Visible = True
                           //lbdelete.Visible = True
                           aimg.Attributes.Add("onclick", "javascript:return winopenaddnews('" + Request["id"] + ViewState["gallery_img"] + "','img');");
                       }
                   }
               }
               else {
                   Response.Redirect("home.aspx");
               }
           }
           else {
               Response.Redirect("home.aspx");
           }
       }
       else {
       }
       //rbEmbed.Checked = True
     }
   }
   //txtTitle.Attributes.Add("onkeypress", "javascript:return checkKey('" & imgbtnSave.ClientID & "',event);")
   //imgbtnSave.Attributes.Add("onclick", "javascript:return valid_news(" & txtTitle.ClientID & "," & File4.ClientID & ");")




谢谢..




Thank you..

推荐答案



narendrarathod写道:
narendrarathod wrote:

if( Convert.ToBoolean((dssubcat.Tables [0] .Rows [0] ["gallery_img"])== System.DBNull.Value?":dssubcat.Tables [0] .Rows [0] ["gallery_img"]) )

if (Convert.ToBoolean((dssubcat.Tables[0].Rows[0]["gallery_img"]) == System.DBNull.Value ? "" : dssubcat.Tables[0].Rows[0]["gallery_img"]))




您实际上是在返回"并将其转换为布尔值.
您注定会出错.您需要返回truefalse而不是".




You are actually returning an "" and trying to convert that to a boolean.
You are bound to get errors. You need to return a true or a false instead of an "".


这篇关于无法将字符串识别为有效的布尔值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 18:26