Cannot convert string to char

I got some help here last night about getting the collection index. Here is the code I'm using.

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            for (int i = 1; i < _prod.ActiveProductItemCollection.Count; i++)
            {

                sb.Append("<script type='text/javascript'>");
                sb.Append("mboxCreate(\"product_productpage_rec{0}\")", i);
                sb.Append("\"entity.id=" + _prodID + "\",");
                sb.Append("\"entity.categoryId=" + _categoryID + "\",");
                sb.Append("\"entity.name=" + _prod.ActiveProductItemCollection[i].Title + "\",");
                sb.Append("\"entity.pageURL=" + Request.Url.ToString() + "\",");
                //The following value has been taken from the productImageControl code behind.
                //Might have to refactor in future as a property of the image control.
                string filename = AppSettingsManager.Current.ProductImagePathLarge + _prod.ActiveProductItemCollection[i].Sku
                    + AppSettingsManager.Current.ProductImageExtension;
                sb.Append("\"entity.thumbnailURL=" + filename + "\",");
                sb.Append("\"entity.inventory=" + _prod.ActiveProductItemCollection.Count + "\",");
                sb.Append("\"entity.value=" + _prod.ActiveProductItemCollection[i].ActualPrice + "\",");
                sb.Append("\"entity.ProductItemID=" + _prod.ActiveProductItemCollection[i].Sku + "\",");
                sb.Append("\"entity.addToCartImg=~/Images/Buttons/btn_AddToCartFlat.gif\");<");
                //The last line has to be /script. < inserted on prev line. do not change it or bad things will happen.            
                sb.Append("/script>");
            }
            this.LiteralMBoxScript.Text = sb.ToString();

What I want to do is get the index of the item in the collection after productpage_rec.

So, for example, the first product will generate, for example,

mboxCreate ("product_productpage_rec1"

etc. etc. for each product in the collection. When I try to build, I get the following error:

"cannot convert from string to char"

Will work on product_productpage_rec {0}

What am I missing?

Thanks in advance.

+3
source share
3 answers
  sb.AppendFormat("mboxCreate(\"product_productpage_rec{0}\")", i);

must work

+6
source

Change it

sb.Append("mboxCreate(\"product_productpage_rec{0}\")", i);

For this:

sb.AppendFormat("mboxCreate(\"product_productpage_rec{0}\")", i);
+3

sb.Append(String.Format("mboxCreate(\"product_productpage_rec{0}\")", i));
0

Source: https://habr.com/ru/post/1770929/


All Articles