DataSource
Before you can manipulate queries with AdHoc, you should set the DataSource property with the datatable that you want AdHoc to build queries from, and then call the DataBind method to bind it to AdHoc.
The following code shows how to:
[C#]
if (!this.IsPostBack)
{
DataTable dtData = new DataTable();
// Load Data, we suppose that the oleDbDataAdapter1 is an OleDbDataAdapter that had established
// a connection and the SqlSelectCommand property are setup also
this.oleDbDataAdapter1.Fill(dtData) ;
this.ahMain.DataSource = dtData;
this.ahMain.DataBind();
}
[VB]
If Not IsPostBack Then
Dim dtData As New DataTable
Me.oleDbDataAdapter1.Fill(dtData)
Me.ahMain.DataSource = dtData
Me.ahMain.DataBind()
End If
"Page" in AdHoc
There 3 steps during generating a query with AdHoc on web page:
1. Select the fields you want to be selected in the result
2. Set the conditions to filter the result
3. Click to make AdHoc to generate the result
Within AdHoc component, we use "Page" to indicate which step the component is in.
The picture below shows the appearance when CurrentPage = 1:
After selecting some fields and click Next, AdHoc goes to second page:
Set the filters and click Next , AdHoc will change to the third page:
If you click "Finish" button, AdHoc will build result automatic with the conditions you specified before.
Get your "filtered" data
As says above, after click "Finish" in third page, AdHoc will build the result and store inside the component.
Further more, clicking "Finish" button of AdHoc will invoke the "Finish" event. You can retrieve the result with accessing the FilteredDataSet, FilteredDataTable or FilteredDataView property while handling the event.
//......
private void InitializeComponent()
{
//.........
this.ahMain.Finish += new AdHoc.FinishEventHandler(this.ahMain_Finish);
}
//......
private void ahMain_Finish()
{
// Variables
System.Data.DataView dvForGrid;
// Assign Value
dvForGrid = ahMain.FilteredDataView;
//Bind to datagrid on page
datagrid.DataSource = dvForGrid;
datagrid.DataBind();
}