Working with DataBlocks (Part 6 of 6)
DataBlocks are a powerful concept in Vidyano in that they help to solve common data oriented tasks such as querying. In this part of the tutorial we will add a new page that will allow us to search for products.
Adding the product management module
- Right-click the AdventureWorksDemo.Module project and select Add -> Vidyano Module...
- Select the AdventureWorksDataContext from the model list and click Finish.
Add a new page
- Open the ProductManagement.mod file by double-clicking it in the AdventureWorksDemo.Module project.
- Click Pages on the left, and click the + Button at the top to create a new Page.
- Name the page Overview and click Next.
- Select the DockPanel and pick the one With Top.
- Click Finish.
Adding the DataBlock
- Click Data Blocks on the left, and click the + Button at the top to create a new Data Block.
- Select the Product entity, since we will be searching for products.
- Set the name to ProductsByName and the scope to Overview.
- Leave Fetch Size blank and Auto Execute Query selected, then click Finish.
Configuring the Data Block
- On the Data Block designer page, change the name of the first property from Text to Name.
- Click the View Code button on the toolbar in the properties section.
- In the Overview constructor, where it says “Initialization code goes here”, write the query. Update the constructor as follow:
public Overview() { this.InitializeComponent();ProductsByName.Query = from p in Module.Context.Products
where p.Name.Contains(ProductsByName.Name) select p;}
Note: Notice how the Name property we created in step a is now used as a parameter in the query.
Displaying the search box
- Go back to the ProductManagement module designer.
- Click on Pages, the Overview page is now visible again.
- Click on the button 1 on PART_1 to start the part generator.
- From the Add Part for PART_1 dialog box, select the LookupTextBox.
- Select the Product entity, the ProductsByName data block and the Name property.
- Uncheck the Show Popup checkbox and click Next.
Figure 29 : The available part generators
Figure 30 : Configuring the LookupTextBox
Binding the search results
- Go back to the ProductManagement module designer.
- Click on the button 2 on PART_2 to start the part generator.
- On the Add Part for PART_2 dialog, select the ListView (Grid) control.
- Configure the ListView to display the Product entity and set the binding to Results (PART_1).
- Select some properties from the left, as in the screenshot above and click Next.
Figure 31 : The Add Data Block dialog

