I have some code in JavaScript
like this:
slider.setPhotos([
{ \"src\": \"image1\", \"name\": \"n1\" },
{ \"src\": \"image2\", \"name\":
Assuming that images
and names
are of same length
You can use this
StringBuilder str = new StringBuilder();
var images = new string[] {"/images/a1.jpg", "/images/a2.jpg", "/images/a3.jpg"};
var names = new string[] {"First", "Second", "Third"};
str.AppendLine("slider.setPhotos([");
for(int i=0; i< images.Length; i++)
{
str.AppendLine("{ \"src\": "+ images[i] +", \"name\": "+ names[i] +" }");
str.AppendLine( (i==images.Length-1 ? "]);":","));
}
Page.ClientScript.RegisterClientScriptBlock(
this.GetType(), "Key007", str.ToString(), true);
This code will insert a script block when your page will be loaded and after that you can use that script block anywhere in your client side code.