Example
Source
Run as server control
DbNetCombo
can be used to provide en effective high-level filtering method for
DbNetGrid
. In this example
DbNetCombo
is used to drill-down through the customer data to select a customer for which
DbNetGrid
displays the orders.
Country
City
Customer
Include the Javascript library file
<script src="<%=ConfigValue( "DbNetComboVirtualDir", false )%>/dbnetcombo.js"></script> <script src="<%=ConfigValue( "DbNetGridVirtualDir", false )%>/dbnetgrid.js"></script>
Styles
td.label { font-weight:bold; }
Client-side script
window.onload = initialise; var countryCombo, cityCombo, customerCombo, dbnetgrid1; ////////////////////////////////////////////////////////////////////////////////////////////// function initialise() ////////////////////////////////////////////////////////////////////////////////////////////// { countryCombo = new DbNetCombo("country") cityCombo = new DbNetCombo("city") customerCombo = new DbNetCombo("customers") with (countryCombo) { connectionString = "suite" sql = "select distinct country, country from customers where country is not null order by 2" addLinkedCombo( cityCombo, "country" ) } with (cityCombo) { connectionString = "suite" sql = "select distinct city, city from customers where country = @country and city is not null order by 2" addLinkedCombo( customerCombo, "city" ) } with (customerCombo) { connectionString = "suite" sql = "select customerid, companyname from customers where city = @city order by 2" onChange = "refreshOrderGrid" } dbnetgrid1 = new DbNetGrid("dbnetgrid1") with (dbnetgrid1) { connectionString = "suite" fromPart = "orders" selectPart = ["orderid", "employeeid", "orderdate", "requireddate", "shippeddate", "freight"] headings = ["Order #", "Taken By", "Date Ordered", "Date Required", "Date Shipped", "Freight Charge"] primaryKeyColumn = "orderid" editRow = false setColumnProperty("freight", "format:c") setColumnLookup("employeeid","employeeid","firstname + ' ' + lastname","employees"); addNestedGrid( configureOrderDetailsGrid, "orderid" ) } countryCombo.load() } ////////////////////////////////////////////////////////////////////////////////////////////// function refreshOrderGrid() ////////////////////////////////////////////////////////////////////////////////////////////// { with (dbnetgrid1) { fixedFilterPart = "customerid = '" + document.getElementById('customers').value + "'" loadData() } } ////////////////////////////////////////////////////////////////////////////////////////////// function configureOrderDetailsGrid( parentGrid ) ////////////////////////////////////////////////////////////////////////////////////////////// { with (parentGrid.childGrid) { displayToolbar = false fromPart = "[order details] inner join products on [order details].productid = products.productid" headings = ["Product","Category","Unit Price","Quantity", "Discount"] selectPart = ["productname", "categoryid", "[order details].unitprice", "quantity", "discount"] setColumnProperty("unitprice", "format:c") setColumnProperty("discount", "format:c") setColumnLookup("categoryid","categoryid","categoryname","categories") loadData() } }
HTML
<table border="1" borderColor="silver" style="border-collapse:collapse" cellpadding="10"> <tr> <td style="background-color:whitesmoke"> <table cellpadding="0" cellspacing="0"> <tr> <td class="label">Country</td> <td> </td> <td class="label">City</td> <td> </td> <td class="label">Customer</td> </tr> <tr> <td><select id="country"></select></td> <td> </td> <td><select id="city"></select></td> <td> </td> <td><select id="customers"></select></td> </td> </table> </td> </tr> <tr> <td id="dbnetgrid1"></td> </tr> </table>