Hello,
I am attempting to bind my WebHierarchicalDataGrid through code using LinqToSQL methods. The parent grid displays and when I click arrow to view the child view, the following error message displays:
[Exception]: DataView has no DataSourceID or DataSource set.
I have the following code to create and bind my DataGrid, DataViews and DataRelations in my Page_Load event handler:
//
//create the OrderHeaders view
Infragistics.Web.UI.DataSourceControls.DataView view = new Infragistics.Web.UI.DataSourceControls.DataView();
//set the properties of the OrderHeaders view
view.ID = "OrderHeadersDataView";
view.DataSource = scRepository.GetOrders(customerNo);
this.WebHierarchicalDataSource1.DataViews.Add(view);
//create the OrderDetails view
view = new Infragistics.Web.UI.DataSourceControls.DataView();
//set the properties of the OrderDetails view
view.ID = "OrderDetailsDataView";
view.DataSource = scRepository.GetOrderDetails(customerNo);
Infragistics.Web.UI.DataSourceControls.DataRelation dr = new Infragistics.Web.UI.DataSourceControls.DataRelation();
dr.ParentDataViewID = "OrderHeadersDataView";
dr.ParentColumns = new string[] { "OrderNo" };
dr.ChildDataViewID = "OrderDetailsDataView";
dr.ChildColumns = new string[] { "OrderNo" };
this.WebHierarchicalDataSource1.DataRelations.Add(dr);
this.whgOrders.DataSourceID = this.WebHierarchicalDataSource1.ID;
this.whgOrders.DataBind();
And markup:
<ig:WebHierarchicalDataGrid ID="whgOrders" runat="server" Height="450px" Width="600px" AutoGenerateColumns="False" AutoGenerateBands="true">
<Columns>
<ig:BoundDataField DataFieldName="OrderNo" Header-Text="Order No" Key="OrderNo" />
<ig:BoundDataField DataFieldName="CustomerPoNo" Header-Text="Cust PO" Key="CustomerPoNo" />
<ig:BoundDataField DataFieldName="RevisedDueDate" Header-Text="Due Date" Key="RevisedDueDate" DataFormatString="{0:d}" />
</Columns>
<Bands>
<ig:Band AutoGenerateColumns="false" DataKeyFields="OrderNo">
<ig:BoundDataField DataFieldName="LineNum" Header-Text="Line No" Key="LineNum" />
<ig:BoundDataField DataFieldName="PartNo" Header-Text="Part No" Key="PartNo" />
<ig:BoundDataField DataFieldName="BuyQtyDue" Header-Text="Qty" Key="BuyQtyDue" DataFormatString="{0}" />
<ig:BoundDataField DataFieldName="RevisedDueDate" Header-Text="DueDate" Key="RevisedDueDate" DataFormatString="{0:d}" />
</ig:Band>
</Bands>
</ig:WebHierarchicalDataGrid>
<ig:WebHierarchicalDataSource ID="WebHierarchicalDataSource1" runat="server">
</ig:WebHierarchicalDataSource>
What am I doing wrong?
Thanks
Steve
Hello steverobinson,
I can take a look at the code behind further. Typically you can set the WebHierarchicalDataSource in the markup of the aspx page. More information can be found here for Binding to Hierarchical Data Source: http://help.infragistics.com/NetAdvantage/ASPNET/2010.3/CLR4.0/?page=WebHierarchicalDataGrid_Binding_to_Hierarchical_Data_Source.html.
Let me know if you have any questions with this matter. Thank you.
Duane,
Thanks for the response. This does seem to work, although expanding the child panes is painfully slow - up to 10 seconds or so to display 1 child record. But that is a different issue. I would still like to know how to bind the data on code behind as it seems to make the grid a bit more flexible. Please let me know what you are able to find.
In the pageload:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not (IsPostBack) Then Grid_LoadData() Else ' Do data binding on grids to enable functionalities. With whdgGrid .DataSource = DataSet ' the dataset can be saved in a session and you could recuperate it. .DataBind() End With End If End Sub
The grid load data:
Protected Sub Seguimiento_ApplyData() With whdgGrid .DataSource = DataSet .DataBind() ' Do other stuff you would like to do with the grid. End With UP_Grid.Update() End Sub
The grid should be looking something like:
<ig:WebHierarchicalDataGrid ID="whdgGrid" runat="server" Width="964px" AutoGenerateColumns="False" AutoGenerateBands="false" EnableAjax="true" EnableAjaxViewState="true" EnableTheming="true" EnableDataViewState="true" StyleSetName="Claymation" DataKeyFields="ID" InitialExpandDepth="0" InitialDataBindDepth="0"> <ExpandCollapseAnimation SlideOpenDirection="Auto" SlideOpenDuration="300" SlideCloseDirection="Auto" SlideCloseDuration="300"/> <AjaxIndicator Enabled="True"/> <Behaviors>...
That is what I am using, I am not using LINQ but if you can construct the DataSource, it should be all okay.
Thanks Estanito for your reply. I ended up getting this to work using a LinqDataSource and handling the OnSelecting event.
protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
e.Result = [linq method to return data] ;
}
Do you have any further questions on the usage of the WebHierarchicalDataSource control? More information on the WebHierarchicalDataSource can be found here: http://help.infragistics.com/NetAdvantage/ASPNET/2010.3/CLR4.0/?page=WebHierarchicalDataGrid_Binding_to_Hierarchical_Data_Source.html.
Unfortunately that very basic sample does not show how to set the datasource in code. It links directly to the database. If you are writing a real world application using an Object model, this example is rather useless. It would be nice for their to be samples with more complex implementations.
Looks like I will ahve to figure out the object structures involved to set it in code.
I found this link via another post (http://community.infragistics.com/forums/p/61535/311397.aspx).
This help doc is titled Using WebHierarchicalDataSource in Code
http://help.infragistics.com/Help/NetAdvantage/ASPNET/2011.1/CLR4.0/html/WebHierarchicalDataSource_Using_WebHierarchicalDataSource_in_Code.html