Search
English
Templating columns for Essential Pack Grid

The RiaGridView control gives you the opportunity to set the contents of the data cells by templates. Applying a template to a column allows you to display data from a linked table, instead of data from the source-table. Editing data in such columns is performed through a drop-down list that contains the records from the linked table. When you change an item from the list, the data in the data source, bound to the RiaGridView control, is changed accordingly.

To create such column, use a field of the TemplateField type. A field of this type, just like any other type of fields, may define headers and a field for sorting. And binding to linked table is done with the template.

To make a template in the RiaGridView, simply specify its EditItemTemplate, placing there the DropDownList component. The items from the drop-down list receive data text and data value from linked and main tables. As a result, a selected item from the list has data text for display and a corresponding data value for editing.


An example of creating a template

A data source, that provides data from the OderDetailDemo table, is bound to the RiaGridView control. Another data source represents the ProductsDemo table with the ProductID column as a primary key, and the ProductName column with the names of the products. In the OderDetailDemo table, there is a ProductID column which is a foreign key to the ProductsDemo table.

You need to display the ProductID column in the OderDetailDemo table, so that it displayed the names of the products instead of corresponding keys. When editing this column, there should appear a drop-down list with the names of the products. Selecting an element from the list causes changing the product key in the OderDetailDemo table in accordance to its name.

To do that, you should:

  1. In the RiaGridView Tasks menu, select Edit Columns.
  2. Creat a field of the TemplateField type, or, if there is a ProductID field in the Selected fields list, convert it to TemplateField. To do that, select the field and press Convert this field into a TemplateField.
  3. When defining the FooterText and HeaderText properties, you need to put a “#” and specify a field (for which you’re creating a pattern ProductID) from a data source, bound to RiaGridView control, after the header.
  4. Click OK to close the Fields dialogue window.
  5. From the RiaGridView Tasks menu, select Edit Templates.
  6. Select EditItemTemplate from the Display drop-down list.
  7. Right-click the default TextBox control in the template and select Delete to remove it.
  8. From the Standard tab of the Toolbox, drag a DropDownList control onto the template.
  9. In the DropDownList Tasks menu, select Choose Data Source.
  10. Select a data source that provides data from the ProductsDemo table.
  11. Select a data field (ProductName) to display in the DropDownList.
  12. Select a data field (ProductID) for the value of the DropDownList.
  13. Click OK.
  14. Select ItemTemplate in the Display drop-down list.
  15. Right-click the default Label control in the template and select Delete to remove it.
  16. In the DropDownList Tasks menu, select Edit DataBindings. The SelectedValue property of the DropDownList control is selected in the DataBindings dialog box.
  17. Click the Field Binding radio button and select a field for Bound To (ProductID).
  18. Uncheck Two-way databinding check box.
  19. Click OK.
  20. In the RiaGridView Tasks menu, click End Template Editing.

    <asp:TemplateField     HeaderText="ProductName#ProductID" SortExpression = "ProductID">
        <EditItemTemplat>
            <asp:DropDownList ID="ddlProductName" runat="server"
            DataSourceID="AccessDataSource1" DataTextField="ProductName"
            DataValueField="ProductID" SelectedValue='<%# Eval("ProductID") %>'>
            </asp:DropDownList>
        </EditItemTemplate>
    </asp:TemplateField>   

The table presents display and editing column values in the TemplateField and BoundField:


              
The field in the ProductName column is of the
TemplateField type
The field in the ProductID column is of the
BoundField type

A few recommendations for setting the RiaGridView control and the data source, when using a template:

The column with a TemplateField should not contain any empty records. This is why, upon making a new record, you should define the DefaultValue for the TemplateField in the InsertParameters list. In this example the InsertParameters list looks like this:


<InsertParameters>
    <asp:Parameter Name="ID" Type="Int32" />
    <asp:Parameter Name="OrderID" Type="Int32"/>
    <asp:Parameter Name="ProductID" DefaultValue="1" Type="Int32"/>
    <asp:Parameter Name="UnitPrice" Type="Single"/>
    <asp:Parameter Name="Quantity" Type="Int16"/>
    <asp:Parameter Name="Discount" Type="Single"/>
</InsertParameters>

Related links

Download Radar-Soft products


Buy Radar-Soft products


Visit our support site


Latest versions
Click to subscribe

 March 9, 2010

RadarCube WinForms Desktop 2.25.0

Changes...Download...

 

 March 9, 2010

RadarCube WinForms MSAS 2.25.0

Changes...Download...

 

 February 26, 2010

RadarCube VCL 1.16.0

Changes...Download...

 

 February 25, 2010

HierCube VCL 4.55.0

Changes...Download...

 

 February 17, 2010

RadarCube ASP.NET 2.35.0

Changes...Download...

 

 July 15, 2009

Essential Pack Pro for ASP.NET 1.11.0

Changes...Download...

 

 July 15, 2009

Essential Pack for ASP.NET 1.11.0

Changes...Download...

 

 November 5, 2008

WinForms Chart 1.00.1

Changes...Download...

 

Related articles
Click to subscribe

 September 30, 2009

RadarCube Request tracker

Details...

 

 August 24, 2009

Customizing the toolbox in Ria OLAP controls

Details...

 

 July 15, 2009

How to localize Essential Pack for ASP.NET

Details...

 

 June 29, 2009

Templating columns for Essential Pack Grid

Details...

 

 June 3, 2009

Customizing RadarCube for ASP.NET

Details...

 

 May 8, 2009

Hierarchy members' attributes

Details...
More articles...
Support | Download | Purchase | Partners | Upgrade and Discount Policy | Contacts © 2005-2009 Radar-Soft, L.L.C. All rights reserved.