How to use ActiveReports dynamic binding of data source

When using ActiveReports Report Control online report design, often have such a demand: to design a report, the need for a fixed field, but each time the data to be displayed is different to how we can do dynamic binding data source it?
How to use ActiveReports dynamic binding of data source
Download the latest version of ActiveReports

In fact, it can easily achieve dynamic binding of data source the latest ActiveReports operation by end-line Web Report Designer. ActiveReports line Report Designer major usage scenarios include:

With drag and drop, in Web applications and browser-line design reports
directly connected database, dynamic data sources bind
this article will show you how to use the online report designer ActiveReports dynamic binding of data source.

Specific steps

1, first open the ActiveReports by the end of the online Visual Studio Web Report Designer, its storage path is as follows:

How to use ActiveReports dynamic binding of data source

2, a data source name is set and the data set in the control field DataSetsController layer, the structure simply is to create a table, the table names and field names corresponding to the table.

Codes are as follows:

public ActionResult GetDataSetContent(string id)
{
DataSet data1= returndata();
ArData XmlJsonData = new ArData();
XmlJsonData.DataSet = new ArDataSet();
XmlJsonData.DataSet.Name = "DataSet1";
XmlJsonData.DataSet.Query = new ArQuery();
XmlJsonData.DataSet.Query.DataSourceName = "DataSource1";
XmlJsonData.DataSet.Fields = new
ArField[data1.Tables[0].Columns.Count];
foreach (DataColumn drc in data1.Tables[0].Columns)
{
XmlJsonData.DataSet.Fields[drc.Ordinal] = new
ArField(drc.ColumnName, drc.ColumnName, drc.Caption);

      }
        XmlJsonData.DataSource = new ArDataSource();
        XmlJsonData.DataSource.Name = "DataSource1";
      XmlJsonData.DataSource.ConnectionProperties = new

ArConnectionProperties();
XmlJsonData.DataSource.ConnectionProperties.DataProvider =
"DATASET";
string dataSet = JsonHelper.ObjTranJson(XmlJsonData);
return new ContentResult { Content = dataSet, ContentType =
"application/json" };
}
public DataSet returndata()
{
DataTable dt = new DataTable();
dt.Columns.Add("产品编号");
dt.Columns.Add("产品名称");
dt.Columns.Add("单价");
dt.Columns.Add("库存量");
dt.Columns.Add("产地");
dt.Rows.Add("A001", "苹果", 10, 300, "中国");
dt.Rows.Add("A002", "葡萄", 20, 200, "中国");
dt.Rows.Add("A003", "香蕉", 30,400, "China");
dt.Rows.Add ( "A004", "sugar cane", 10, 300, "China");
dt.Rows.Add ( "A005", "lychee", 20, 200, "China");
dt.Rows.Add ( "A006", "mango", 30, 400, "China");
dt.Rows. Add ( "A007", "kiwi", 110, 300, "China");
dt.Rows.Add ( "A008", "lemon", 210, 200, "China");
dt.Rows.Add ( "A009 "" chestnut ", 320, 400," China ");
dt.Rows.Add (" A010 "," dragon fruit ", 100, 300," China ");
dt.Rows.Add (" A011 "," Qingmang ", 250, 200," China ");
dt.Rows.Add (" A012 "," Almond ", 320, 200," China ");
dt.Rows.Add (" A013 "," potatoes "380, 400" China ");
dt.Rows.Add (" A014 "," Apple ", 110, 300," China ");
dt.Rows.Add ("A015 "," grape ", 420, 200," China ");
dt.Rows.Add (" A016 "," banana ", 530, 400," China ");
dt.Rows.Add (" A017 "," potato ", 380, 400," China ");
dt.Rows.Add (" A018 "," Apple ", 110, 300," China ");
dt.Rows.Add (" A019 "," grape ", 420 200, "China");
dt.Rows.Add("A020", "香蕉", 530, 400, "中国");
dt.Rows.Add("A021", "苹果", 10, 300, "中国");
dt.Rows.Add("A022", "葡萄", 20, 200, "中国");
dt.Rows.Add("A023", "香蕉", 30, 400, "中国");
dt.Rows.Add("A024", "甘蔗", 10, 300, "中国");
dt.Rows.Add("A025", "荔枝", 20, 200, "中国");
dt.Rows.Add("A026", "芒果", 30, 400, "中国");
DataSet temp = new DataSet();
temp.Tables.Add(dt);
return temp;
}
[Route("list")]
[HttpGet]
public ActionResult GetDataSetsList()
{
var dataSetsService =
HttpContext.GetServiceFromContext();
//var dataSetsList = dataSetsService.GetDataSetsList();
//return Json(dataSetsList, JsonRequestBehavior.AllowGet);
return Json (new object [] { new {Id = "test", Name = " Add Data"}},
JsonRequestBehavior.AllowGet);
}
. 3, statements need to create a good binding data, It should be noted that: during data binding, sure to make the corresponding dynamic data source bindings in Startup.cs where else will complain in the report preview.

The main codes are as follows:

app.UseReporting (config = \>
{
config.UseFileStore (ResourcesRootDirectory);
config.LocateDataSource = args = \>
{
DataSetsController TemCon new new DataSetsController = ();
the DataSet DATAl TemCon.returndata = ();
return DATAl;
};
});
4, complete the above steps, you can achieve dynamic binding of data source in ActiveReports line report Designer, let's take a look at the specific operating style:

How to use ActiveReports dynamic binding of data source
How to use ActiveReports dynamic binding of data source
How to use ActiveReports dynamic binding of data source

Guess you like

Origin blog.51cto.com/14452385/2424638