How to: Provide a Value to a Query Parameter

By binding a parameter to a field in a screen, you can enable users to provide the value of a query parameter.

Users can provide a value either directly or implicitly. They can type the value directly into a text box or they can select an item from a related list on the screen. For example, to view a list of sales orders, a user can type the ID number of a customer or select a customer from a customer list.

To enable users to type a value, bind the parameter to a field in the screen. To enable users to provide the value implicitly, bind the parameter to a field in a list that appears on the screen. For example, you might bind the CustomerID parameter of an Orders query to the CustomerID field of a Customers list.

link to video For a related video demonstration, see How Do I: Pass a Parameter into a Screen from the Command Bar in a LightSwitch Application?.

To Bind a Query Parameter to a Field

  1. Create a query that accepts a parameter (for example: the ID of a customer). For more information, see How to: Design a Query by Using the Query Designer.

  2. Add the query to the Screen Content Tree. For more information, see How to: Design a Silverlight Screen by Using the Screen Designer.

  3. Add a local field to the screen. For more information, see How to: Add a Local Property to a Silverlight Screen.

  4. In the Screen Members List of the Screen Designer, select the parameter of the query.

  5. On the View menu, click Properties Window.

  6. Select the Parameter Value text box.

  7. Select or type the name of the local field.

To Bind a Query Parameter to a Field in a List

  1. Create a query that accepts a parameter (for example: the ID of a customer). For more information, see How to: Design a Query by Using the Query Designer.

  2. Add the query to the Screen Content Tree. For more information, see How to: Add Data to a Screen.

  3. Add a second query to the Screen Content Tree. Make sure that the entity returned by this query contains a field that matches the parameter of the first query.

    For example, if the first query accepts a customer ID as a parameter, make sure that the second query returns an entity that contains a customer ID field.

  4. In the Screen Members List of the Screen Designer, select the parameter of the query.

  5. On the View menu, click Properties Window.

  6. Select the Parameter Value text box.

  7. Select or type the fully qualified name of a field from the second query (for example: CustomerList.SelectedItem.CustomerID).

Next Steps

To learn how provide parameter values to a query by using code, see How to: Retrieve Data from a Query by Using Code.

See Also

Tasks

How to: Add, Remove, and Modify a Query

Walkthrough: Designing a Screen

How to: Design a Query by Using the Query Designer

How to: Retrieve Data from a Query by Using Code

Other Resources

Queries: Retrieving Information from a Data Source