Additional Information
Questions
How do I display the CompanyName for a column containing a CustomerID ?
How do I allow the user to select the CompanyName from a drop-down-list for a column containing a CustomerID?
Solution
If the grid or column is display only (no editing), the CompanyName can be displayed in a column containing a CustomerID by using a ValueList. See tutorial Value Lists. If the column is editable, The CompanyName can be displayed in a column containing a CustomerID by setting the value list to a web combo control.
To provide a multi-column drop-down-list for a column, set the value list to a WebCombo control.
Step-By-Step Example
This sample project retrieves the Northwind Orders database and binds an UltraWebCombo control to the CustomerID column to display the CompanyName. The UltraWebCombo control is populated with values from the Northwind Customers table and displays as a multi-column drop-down when the user selects the cell for editing.Code Discussion
Web_Combo_In_Grid_Cell.aspx
Web_Combo_In_Grid_Cell.aspx contains the code relevant to this project and consists of the following code regions:
Page Events
The Page Events Region contains the following event handlers:
Page_Load - The Page_Load event contains code to retrieve the Northwind Orders and Customers and bind them to the grid and combo. First, declare a new data connection and retrieves the connection string:
Declare a data adapter to retrieve the CustomerID and CustomerName fields from the Customers database. Declare a new data table and fill it with data. Tell the web combo control which column to use as the DataValueColumn and which column to use as the DisplayValueColumn, set the data source to the Customers data table and bind the data to the control.
Declare a data adapter to retrieve rows from the Orders database. Declare a new data table and fill it with data using the data adapter. Set the data source of the grid to the data table and bind the data to the grid.
UltraWebGrid Events
The UltraWebGrid Events Region contains the following event handlers:
UltraWebGrid1_InitializeLayout - The UltraWebGrid InitializeLayout event contains code to set the layout properties of the control:
To make the grid editable, set the CellClickAction property to Edit and set the AllowUpdate property to Yes
To bind the web combo to the CustomerID column, set the Type property to DropDownList, set the ValueList.WebCombo control to the WebCombo1 control. To set the column to display the text rather than the value, set the DisplayStyle property to DisplayText.
Format the date columns to make them look a little better.
UltraWebCombo Events
The UltraWebCombo Events Region contains the following event handlers:
WebCombo1_InitializeLayout - The web combo control defaults the column widths to about 100 pixels. To display more of the CompanyName column, set the width to about 300 pixels: