Version

Getting Started with WebHierarchicalDataGrid

Before You Begin

WebHierarchicalDataGrid™ allows many features to be enabled for complex behaviors and dynamic operations. The most common use however, is to display data. Binding and displaying data with WebHierarchicalDataGrid is a simple process. It can bind to many forms of hierarchical data sources. One convenient way to obtain hierarchical data is by using WebHierarchicalDataSource™. For more information on using the WebHierarchicalDataSource component to bind to data, see Getting Started with WebHierarchicalDataSource.

What You Will Accomplish

You will learn how to bind WebHierarchicalDataGrid to the WebHierarchicalDataSource component using the Northwind Categories and Products table.

Follow these Steps

  1. Create an ASP.Net web page.

  2. Drag a ScriptManager component from the toolbox onto the page.

  3. Drag a WebHierarchicalDataGrid control from the toolbox onto the page.

  4. Drag a WebHierarchicalDataSource component from the toolbox onto the page.

Note
Note:

If you already know how to set up WebHierarchicalDataSource, set the component to retrieve the Categories and Products data with a parent-child relationship, and skip to step 26.

  1. Click WebHierarchicalDataSource’s Smart Tag and select Edit Relations. The Quick Design appears.

WebHierarchicalDataSource Getting Started with WebHierarchicalDatasource 01.png
  1. Click the Add View option.

  2. Select New Data Source from the drop-down list that appears.

Note
Note:

If you have data sources readily available on your page at this time, these data sources will appear in the drop-down list. If you have multiple views in a data source, they are selectable in the DataView drop-down list.

The Data Source Configuration Wizard appears.

WebHierarchicalDataSource Getting Started with WebHierarchicalDatasource 02.png
  1. Select Database.

  2. Click OK.

  3. WebHierarchicalDataSource adds a SqlDataSource component to the form and the Configure Data Source wizard appears for the SqlDataSource component.

WebGrid Binding WebGrid To SQL Data Source 01.png
  1. Click New Connection to configure the connection string. The Add Connection dialog appears.

WebGrid Binding WebGrid To SQL Data Source 02.png
  1. Set the server name to the server you are using, SQLEXPRESS in this case. Set the database to Northwind.

  2. Click Ok. You are returned to the Configure Connection screen.

  3. Click Next.

  4. Select Specify Columns from a Table or View and do the following:

    1. Choose the Categories table from the drop-down list.

    2. In the Columns section, select CategoryID, CategoryName, and Description to display those columns.

    3. At this point you have the option to click the Advanced button to specify that the SqlDataSource component should generate Insert, Update, and Delete statements for the data retrieved.

  1. Click Next.

  2. Test your query to make sure SqlDataSource retrieves your data.

  3. Click Finish to close the configuration wizard. SqlDataSource is set up to retrieve the Categories data from the Northwind database.

  4. Click Ok to return to the Quick Design. You will see the SqlDataSource you just added.

WebHierarchicalDataSource Getting Started with WebHierarchicalDatasource 03.png
  1. Click the Add Child node directly under the SqlDataSource1 node. The child configuration screen appears.

Note
Note:

You can also add a sibling node for the existing data source at this point by clicking on the Add View link at the same level of the added data source.

  1. Select New Data Source in the Child DataSource drop-down list.

Note
Note:

At this point, you can also select the first data source to create a self-related view. For more information, see Creating a Self-Related Data Relation.

  1. Repeat steps 8 – 12 for the second SqlDataSource, this time choosing the Products table with all columns selected.

  2. Add the relation between the two data sources by selecting the columns for the relationship.

    1. Select CategoryID in the Parent Columns drop-down list.

    2. Select CategoryID in the Child Columns drop-down list.

Note
Note:

You can relate tables by selecting additional columns based on a composite key. For more information, see Add a Composite Key Relationship.

WebHierarchicalDataGrid Binding to Data 01.png
  1. Click Ok to return to the Quick Design view.

  2. At this point, WebHierarchicalDataSource is ready to use two SQL data sources to display hierarchical data. Click Apply then Ok.

  3. Set WebHierarchicalDataGrid’s DataSourceID property to WebHierarchicalDataSource1 in the Properties window. You will be prompted to Refresh Bands, Columns, and Keys for WebHierarchicalDataGrid.

  4. Click Yes. This will automatically set the DataMember and Key properties to SqlDataSource1_DefaultView, which is the name of the first data view that you set up in WebHierarchicalDataSource.

WebHierarchicalDataGrid Binding to Data 02.png
  1. Run the application. WebHierarchicalDataGrid displays a hierarchical view of the Categories and Products tables.

WebHierarchicalDataGrid Binding to Data 03.png