cannot convert string to char
I got some help on here last night about getting an the index of a collection. 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);
开发者_Python百科 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 instance, the first product would generate like
mboxCreate("product_productpage_rec1"
and so on and so forth for each product in the collection. When I try to build I get the follwong error:
"cannot convert from string to char"
Its tripping up on the product_productpage_rec{0}
What am I missing?
Thanks in advance.
sb.AppendFormat("mboxCreate(\"product_productpage_rec{0}\")", i);
should work
Change this
sb.Append("mboxCreate(\"product_productpage_rec{0}\")", i);
To this:
sb.AppendFormat("mboxCreate(\"product_productpage_rec{0}\")", i);
You need to use
sb.Append(String.Format("mboxCreate(\"product_productpage_rec{0}\")", i));
精彩评论