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

问题描述

您好,首先是我的英语不好。在我的项目中ı一直试图从代码behing中显示值但是ı得到这个消息甚至已经检查变量是否为空



编译器错误消息:CS0201:只有赋值,调用,递增,递减,等待和新对象表达式才能用作语句

Hello , first sory my poor english. In my project ı have been trying to display value from code behing but ı get this mesage even ı have checked the variable is null or not

Compiler Error Message: CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

<br />

                         <div class="prod_price_big"><span class="reduce">350$</span>&lt;%if (Price != null) { %&gt; &lt;% Price;
                                                                                       }%&gt; <span>





我背后的代码是



and my code behind is

public Users user
      {
          get { return Session["user"] as Users; }
          set { Session["user"] = value; }
      }

      ShipperResposite _shiperResposite = new ShipperResposite();
      decimal Pricee;
      public decimal Price
      {
          get { return Price; }
          set
          {
              value = Pricee;
              Price = value;
          }
      }

      protected void Page_Load(object sender, EventArgs e)
      {
          if (user == null)
              Response.Redirect("~/Default.aspx", true);
          if(Price==null)
              Response.Redirect("~/Default.aspx", true);

          DropDownList1.DataSource = _shiperResposite.ListShippers().ToList();
          DropDownList1.DataTextField = "CompanyName";
          DropDownList1.DataValueField = "ID";
          DropDownList1.DataBind();
          Pricee = _shiperResposite.GetPriceFromID(Convert.ToInt32(Request.QueryString["ID"]));

      }


      }
  }</span></div>

推荐答案





我背后的代码是



and my code behind is

public Users user
      {
          get { return Session["user"] as Users; }
          set { Session["user"] = value; }
      }

      ShipperResposite _shiperResposite = new ShipperResposite();
      decimal Pricee;
      public decimal Price
      {
          get { return Price; }
          set
          {
              value = Pricee;
              Price = value;
          }
      }

      protected void Page_Load(object sender, EventArgs e)
      {
          if (user == null)
              Response.Redirect("~/Default.aspx", true);
          if(Price==null)
              Response.Redirect("~/Default.aspx", true);

          DropDownList1.DataSource = _shiperResposite.ListShippers().ToList();
          DropDownList1.DataTextField = "CompanyName";
          DropDownList1.DataValueField = "ID";
          DropDownList1.DataBind();
          Pricee = _shiperResposite.GetPriceFromID(Convert.ToInt32(Request.QueryString["ID"]));

      }


      }
  }</span></div>


if (Price != null) { %><% Price; }





Price是一个变量,你将它用作表达式。我建议将Price作为永不返回null的属性,并将所有这些替换为= Price。替代方案是用Response.Write(Price)替换Price,Price本身不是输出该变量的语句,并且它没有值,并且创建错误(这不是空引用,这就是为什么它在任何地方都不会说''null'。



两个代码块也搞砸了你。摆脱中间的,我引用的那些。



Price is a variable, and you''re using it as an expression. I would suggest making Price a property that never returns null, and replacing all of this with =Price. The alternative is to replace Price with Response.Write(Price), Price by itself is not a statement to output that variable, and it has no value, and creates the error ( which is NOT a null reference, that''s why it doesn''t say ''null'' anywhere ).

The two code blocks are also messing you up. Get rid of the middle ones, the ones I quoted.


}

    ı have revize my code like this 

 public decimal Price
        {
            get { return Price; }
            set
            {
                Price=_shiperResposite.GetPriceFromID(Convert.ToInt32(Request.QueryString["ID"]));
                Price = value;
            }
        }



 

and ı have changed my code like this at html side

 <div class="prod_price_big"><span class="reduce">350


这篇关于如何显示价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 06:22