FlexMonster Pivot Table Component can be integrated with .NET
We will guide you through simple C# integration sample.
To integrate Pivot Table into your page you should accomplish the following steps:
<script type="text/javascript" src="swfobject.js"></script>
<div id="flashContent">No Flash player or Javascript disabeled message</div>
<script type="text/javascript">
var so = new SWFObject("PivotTable.swf", "flash", "1000", "720", "9", "#FFFFFF");
so.addParam("allowScriptAccess", "sameDomain");
so.addParam("menu", "false");
so.addParam("allowFullScreen", "true");
so.addVariable("filename", "your_data_script.aspx");
so.addVariable("styleSheetName", "original.css");
so.addVariable("configuratorEnabled", "true");
so.addVariable("chartsEnabled", "true");
so.write("flashContent");
flash.focus();
</script>
so.addVariable("filename", "your_data_script.aspx");
First of all you we need to inform you that best data format for Pivot Table Component is CSV. So now we will write simple CSV generator. You can use external library or create your own. No matter.
Our script has two methods:
protected DataTable GetData() {
if (DataTable != null) return DataTable;
if (DBConnectionString == null || SQLQuery == null) throw new Exception("Please provide either DataRows, or both DBConnectionString and SQLQuery to get data");
SqlConnection conn = new SqlConnection(DBConnectionString);
SqlDataAdapter da = new SqlDataAdapter(SQLQuery, conn);
DataSet ds = new DataSet();
da.Fill(ds, "table0");
conn.Close();
return ds.Tables["table0"];
}
public string GenerateCSVToString() {
DataTable data = GetData();
MemoryStream stream = new MemoryStream();
CsvWriter writer = new CsvWriter(stream);
ArrayList columns = new ArrayList();
foreach (DataColumn col in data.Columns) {
columns.Add(col.ColumnName);
}
object[] colsObject = new object[columns.Count];
columns.CopyTo(colsObject);
writer.WriteFields(colsObject);
foreach (DataRow r in data.Rows) {
int i = 0;
foreach (DataColumn col in data.Columns) {
colsObject[i] = r[col];
i += 1;
}
writer.WriteFields(colsObject);
}
writer.Flush();
stream.Position = 0;
using (StreamReader reader = new StreamReader(stream)) {
// Just read to the end.
return reader.ReadToEnd();
}
}
You can download full source code of this sample.