Have you considered just creating a custom web control. I created a quick one that takes an array of [,] and just prints the contents of the array into a div with p around each value of the array. Its simple, easy and you will have full control over the exit.
Below is the step you need to complete:
Add a new project to your web application and make sure you link to System.web. Perhaps call the WebControls project.
Add the following C # code to a new class file that you can add to the project.
CUSTOM CONTROL CODE:
using System.ComponentModel; using System.Web.UI; using System.Web.UI.WebControls; namespace WebControls { [ToolboxData("<{0}:ArrayDisplayControl runat=server></{0}:ArrayDisplayControl>")] public class ArrayDisplayControl : WebControl { protected override HtmlTextWriterTag TagKey { get { return HtmlTextWriterTag.Div; } } public string[,] DataSource { get { return (string[,])ViewState["DataSource"]; } set { ViewState["DataSource"] = value; } } protected override void RenderContents(HtmlTextWriter output) { output.WriteBeginTag("div"); for (int i = 0; i < DataSource.GetLength(0); i++) { for (int j = 0; j < DataSource.GetLength(1); j++) { output.WriteFullBeginTag("p"); output.Write(DataSource[i, j]); output.WriteEndTag("p"); } } output.WriteEndTag("div"); } } }
Now you only need to update your recently added project in your web application. properties β add link - select projects, and then the name of the new project.
Well, all thatβs left is to add an ad at the top of the asp.net page so that you can link to the custom control as follows:
<%@ Register Assembly="WebControls" Namespace="WebControls" TagPrefix="custom" %>
Now reference the control in html, as shown below:
<custom:ArrayDisplayControl ID="ctlArrayDisplay" runat="server" />
So the last step is to bind the control to some data in the code behind - something like the following:
protected void Page_Load(object sender, EventArgs e) { string[,] data = new string[2, 2] { { "Mike", "Amy" }, { "Mary", "Albert" } }; ctlArrayDisplay.DataSource = data; ctlArrayDisplay.DataBind(); }
And here is the result after launch:
<div id="ctlArrayDisplay"> <div><p>Mike</p><p>Amy</p><p>Mary</p><p>Albert</p></div> </div>
Hope this helps you get rid of your jam.
Enjoy it!