Navigation: Helper Classes >

Lookup

 

 

 

 

 

The Lookup class is designed to help with assignment of a Lookup to a column

 

...

ordersGrid.Column("ShipVia").Lookup(new Lookup("Shippers","ShipperID", "CompanyName"));

ordersGrid.Column("EmployeeId").Lookup(new Lookup("Employees", "EmployeeID", "FirstName + ' ' + LastName"));

...

 

Constructors

 

Lookup(string fromPart, string foreignKeyColumn, string descriptiveColumn = null, bool distinct = false)

 

fromPart - The name of the lookup table or view

foreignKeyColumn - The foreign key column against which the grid value is matched

descriptiveColumn - The description column expression that will be substituted in the grid display or displayed in the column filter or search lookup

distinct - Selects distinct values only (optional)

 

...

ordersGrid.Column("ShipVia").Lookup(new Lookup("Shippers","ShipperID", "CompanyName"));

ordersGrid.Column("EmployeeId").Lookup(new Lookup("Employees", "EmployeeID", "FirstName + ' ' + LastName"));

...

     

Lookup(string sql)

 

sql - SQL select statement

 

This version of the constructor provides greater flexibility in terms of the way lookup data is selected as it can include additonal clauses such as where and order by.

...

tasksGrid.Column("ShipVia").Lookup(new Lookup("select Value, Description from Lookup where Category = 'PROJECT'"));

...

 

The sql argument can also be used to include a parameter which is populated at run time with a value from a column with the same name as the parameter e.g.

...

customersEdit.Column("country").Lookup(new Lookup("select distinct country from customers where region = @region"));

customersEdit.Column("city").Lookup(new Lookup("select distinct city from customers where country = @country"));

...

  

In this example the country lookup includes the @region parameter which is automatically populated by the value in the region column so that only countries for the selected region are shown. The same principle applies to the city lookup which in turn only shows cities for the selected country.

 

 

 

Copyright © 2023 DbNetLink