Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
OpenAccessDataSource QuickStart Example
Programmer's Guide > OpenAccess ORM Classic (Old API) > Programming With OpenAccess > Data Toolbox Controls > OpenAccessDataSource Web Server Control Overview > Data Selection using OpenAccessDataSource > OpenAccessDataSource QuickStart Example

Glossary Item Box

This documentation article is a legacy resource describing the functionality of the deprecated OpenAccess Classic only. The contemporary documentation of Telerik OpenAccess ORM is available here.

The example in this topic demonstrates use of the OpenAccessDataSource control to implement a data binding scenario. The example application displays Order items. The data model used in the application is based on the Northwind sample database. The completely developed model project is available in our Code Library.

The following screen display shows the tool in use. A list box on the left side of the page contains identity keys of Order items. In the display, Order number 43666 has been clicked. The associated SalesOrderDetail items are displayed by the Gridview control on the right.

[picture]

 The example is implemented in the following stages:

    *  Create an ASP.NET Web application.
    *  Add a RadComboBox to display Order keys.
    *  Add a RadGrid control to display associated OrderDetail items.
    *  Add and configure two OpenAccessDataSource controls to supply data to the RadComboBox and RadGrid controls.
    *  Add an event handler for the list box selected-index changed event.

Create an ASP.NET Web application

This procedure creates the ASP.NET application.

To create the ASP.NET Web application:

  1.  In the project containing the northwind data model, right click on the solution and choose Add->New Project.
  2. In the pop up menu choose ASP.Net application.
  3. Click OK.

Adding Controls to Display Data

 This procedure adds the two data controls that are needed to display the Order keys and associated OrderDetail items.

To add display controls to the page:

  1. Open the Default.aspx design view in Visual Studio and drag the div boarder down so that there is enough room to add controls to the page.
  2. Add a label with text: Select OrderID.
  3. Below the label add a RadComboBox. The default ID, RadComboBox1, can be used. Set the size and position of the combo box according to the page mark-up at the bottom of this page.
  4. Add a RadGrid control to the page and set the position according to the page mark-up at the bottom of this topic. The default ID RadGrid1 can be used.
  5. Add a label above the GridView control with text: OrderID.
  6. Add another label above the GridView. This label will be used in a parameter of a CommandText. Give it an ID that reflects its purpose.
  7. Set the visibility of this label to false.

Adding and Configuring OpenAcceesDataSource Controls

These procedures create the OpenAccessDataSource controls and bind the display controls to these data source controls.

To add the OpenAccessDataSource controls:

  1.  Add an OpenAccessDataSource control to the page. The default OpenAccessData1 can be used. This control will be bound to RadComboBox1 to display Order keys.
  2. Add another OpenAccessDataSource control to the page. The default OpenAccessData2 can be used. This control will be bound to the RadGrid1 to displayOrderDetail entities associated with the Order identity key selected by the user in RadComboBox1.
    At this point you should rebuild your project so the next steps can work for you.

To binding the rad combo box control to the OpenAccessData1 data source

  1. Click the > symbol on the OpenAccessDataSource control.
  2. Click Configure Data Source.
  3. When the Configure Object Context dialog box appears, select NortwhindMapping.ObjectScopeProvider1 from the drop-down list.
  4. From the persistent type drop down list choose NorthwindMapping.OrderDetail
  5. Click Finish.
  6. Click the > symbol on RadComboBox1, and select Choose Data Source.
  7. When the Choose a Data Source dialog box appears, choose OpenAccessData1 from the Select a Data Source drop-down list. Select OrderID in the next two drop down lists.
  8. Click OK.

To bind the grid view control to the SalesOrderDetail data source

  1.  Select the OpenAccessDataSource control named OpenAccessData1 on the design surface of the Default.aspx page.
  2. Click the > symbol on the OpenAccessDataSource control.
  3. Click Configure Data Source.
  4. When the Configure Object Context dialog box appears, select NortwhindMapping.ObjectScopeProvider1 from the drop-down list.
  5. From the persistent type drop down list choose NorthwindMapping.OrderDetail
  6. Click Filter.
  7. In the property drop down list select OrderId
  8. From the operator drop down list select ==
  9. From the source drop down list select Control
  10. From controlID select the label that you have earlier set to invisible.
  11. Click Add.
  12. Click Finish.

Defining the Selected-Index Change Event Handler for the Rad Combo Box

This final procedure connects the user's selection of an identity key for a Order to a query that returns properties of all OrderDetail entities associated with the selected OrderID.

To create an event handler for the SelectedIndexChanged event of RadComboBox1:

  1. Select RadComboBox1 in the Web page design surface.  
  2. Right-click RadComboBox1, and select Properties.
  3. In the Properties list, click the events option.
  4. Double-click the SelectedIndexChanged event. This opens the ASP.NET code-behind page, Default.aspx.cs or Default.aspx.vb, and shows the code block for the event handler.
  5. Add the following code to the event handler:
    even code Copy Code
    myLable.Text = RadComboBox1.SelectedValue.ToString();
               RadGrid1.DataSource = OpenAccessDataSource2;
               RadGrid1.DataBind();
  6. Set the AutoPostBack property of RadComboBox1 to true, so the server can read the selection as soon as it is made.

When the SelectedIndexChanged event fires, the predefined query with the parameterized Where clause runs. The properties displayed in RadGrid1 are those of OrderDetail entities associated with the OrderID selected in RadComboBox1.