I have a strongly-typed dataset (data.xsd) with 2 datatables and a relation defined between the 2 tables. The UltraWebGrid viewtype is set to Hierarchial.
How do I set the UltraWebGrid.DataSource to display the hierarchial data represented in data.xsd?
I tried setting it to the parent table in the dataset, but I did not get the hierarchial view of the grid.
Thanks.
Don Sharp
You can check out this example for complete source code on how to bind the grid to a hierarchical dataset. Here is some sample code:
protected void UG1_DataBinding(object sender, System.EventArgs e) { oleDbConnection1.ConnectionString = WebSamplesCS.Config.NorthwindMDBConnString; OleDbDataAdapter cmdCustomers= new OleDbDataAdapter("Select CustomerID,CompanyName,ContactName,ContactTitle,Phone,Address from Customers", oleDbConnection1); OleDbDataAdapter cmdOrders = new OleDbDataAdapter("Select CustomerID,OrderID,OrderDate,ShippedDate,ShipAddress,Freight from Orders", oleDbConnection1); cmdCustomers.Fill(contactsDataSet1, "Customers"); cmdOrders.Fill(contactsDataSet1, "Orders"); try { contactsDataSet1.Relations.Add("Customers", contactsDataSet1.Tables["Customers"].Columns["CustomerID"], contactsDataSet1.Tables["Orders"].Columns["CustomerID"]); } catch (System.Exception x) { string s = x.Message; string m = s; } this.UG1.DataSource = contactsDataSet1.Tables["Customers"].DefaultView; }
Also, please make sure you have set
ViewType="Hierarchical"
in the DisplayLayout section of the grid.
The example uses an OleDbDataAdapter with inline SQL. I am using a strongly-typed dataset (an xsd file) that has a similar structure to the OleDbDataAdapter in the example, but when I set the .DataSource to the parent table in the xsd file, I do not get the hierarchical view of the data as defined by the relation object in the xsd file.
Here is the code for the xsd dataset:
<
</
The code to set the datasource of the grid (uwgExposures_Data) is:
taGetExposureSummaryData =
dtGetExposureSummaryData = taGetExposureSummaryData.GetSummaryData();
uwgExposures_Data.DataSource = dtGetExposureSummaryData;
(the ViewType is set to "Hierarchical")
What am I doing wrong??
I got it to work by just binding the UltraWebGrid to the entire structured dataset (not just the first table). In my example, I call my web service which returns a structured dataset. This dataset has 4 tables and 3 relations and 3 levels. I just bind that whole dataset to my UltraWebGrid and it shows all of the data with the expand/collapse buttons on each row. Note: you need to set the grid's DisplayLayout/ViewType = Hierarchical.
Dim oDS as New MyWebService.MyStructuredDataSet
oDS = oMyWebService.GetMyDataset()
UltrawebGrid1.DataSource = oDS
UltraWebGrid1.DataBind()