1

我正在尝试从下面的会话中放置文本,因此它基本上是 Product1、Product2、Product3 等等...此外,如果会话包含文本“选择 ....”以将其替换为“”当我运行下面的代码我得到错误运算符'+'没有为类型'ListItem'和字符串“,”定义。

NameofProduct = Session("Product1") + "," + Session("Product2").Replace("Select....", "") + ","  + Session("Product3") + "," + Session("Product4") + "," + Session("ProductManual")
4

4 回答 4

5

您正在尝试连接objects在一起,而是这样做:

NameofProduct = Session("Product1").ToString() + "," + Session("Product2").ToString().Replace("Select....", "") + ","  + Session("Product3").ToString() + "," + Session("Product4").ToString() + "," + Session("ProductManual").ToString()
于 2013-07-02T15:04:44.580 回答
2

为了可维护性,使用 StringBuilder:

Dim sb as new StringBuilder
sb.AppendFormat("{0},", Session("Product1"))
sb.AppendFormat("{0},", Session("Product2").Replace("Select....", ""))
sb.AppendFormat("{0},", Session("Product3"))
sb.AppendFormat("{0},", Session("Product4"))
sb.AppendFormat("{0}", Session("ProductManual")
NameofProduct = sb.ToString()
于 2013-07-02T15:16:27.223 回答
1

只是好奇你试过&运营商吗???

NameofProduct = Session("Product1") & "," & Session("Product2").Replace("Select....", "") & "," & Session("Product3") & "," & Session("Product4") & "," & Session("ProductManual")

试试看

于 2013-07-02T15:20:15.480 回答
0

IMO 在连接的所有部分尝试 Session("Product1").ToString() ;你会发现它们并不都是字符串...

于 2013-07-02T15:05:21.923 回答