Articles in this section
Category / Section

How to render Pivot component with Data Table in .NET WebForms ?

1 min read

This KB illustrates that how to render Pivot component with Data Table.

Solution:

You can render the pivot components in relational server mode by using the DataTable as DataSource. You can also perform the operations supported by the respective pivot controls. Refer to the following code snippets.

Step 1

In the relational Web API controller, add the following class. Using the GetSQLResult method, you can get data from the local database.

public class DbaseQuery
{
public dynamic GetSQLResult()
{
//-local path of database file(mdf) for sql com
  string conSTR = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + AppDomain.CurrentDomain.BaseDirectory + @"App_Data\Database1.mdf;Integrated Security=True";
 string xquery = "SELECT * FROM table1";
 SqlConnection sqlConn = new SqlConnection(conSTR);
 sqlConn.Open();
 SqlCommand cmd = new SqlCommand(xquery, sqlConn);
 SqlDataAdapter da = new SqlDataAdapter(cmd);
 DataTable dt = new DataTable();
 da.Fill(dt);
 
 for (var i = 0; i < dt.Rows.Count; i++)
  {
for (var j = 0; j < dt.Rows[i].ItemArray.Length; j++)
  {
    dt.Rows[i].ItemArray[j] = dt.Rows[i].ItemArray[j].ToString().Trim();
}
 }
 
 return dt;
}
}

Step 2

You should pass the above DataTable as parameter, which is returned from GetSQLResult method in every action such as InitializeClient and nodeDropped of the respective pivot component.

public class RelationalController : ApiController
{
DbaseQuery dbquery = new DbaseQuery();
//…
 
//Here we have used PivotGrid control. You can render other supported Pivot components (PivotClient, PivotChart, PivotGauge) too.
 
[System.Web.Http.ActionName("InitializeGrid")]
System.Web.Http.HttpPost]
public Dictionary<string, object> InitializeGrid(Dictionary<string, object> jsonResult)
{
 
//…
 
var dictionary = htmlHelper.GetJsonData(jsonResult["action"].ToString(), dbquery.GetSQLResult(), jsonResult["valueSorting"].ToString());
 
return dictionary;
}
 
//…
 
[System.Web.Http.ActionName("NodeDropped")]
[System.Web.Http.HttpPost]
public Dictionary<string, object> NodeDropped(Dictionary<string, object> jsonResult)
{
//…
htmlHelper.PopulateData(jsonResult["currentReport"].ToString());
var dictionary = htmlHelper.GetJsonData(jsonResult["action"].ToString(), dbquery.GetSQLResult(), null, jsonResult["dropAxis"].ToString(), jsonResult["headerTag"].ToString(), jsonResult.ContainsKey("filterParams") ? jsonResult["filterParams"].ToString() : null, jsonResult["sortedHeaders"].ToString(), jsonResult["valueSorting"].ToString());
return dictionary;
}
//…
 

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment