|
1 | | -<!-- default badges list --> |
2 | | - |
3 | | -[](https://supportcenter.devexpress.com/ticket/details/E3653) |
4 | | -[](https://docs.devexpress.com/GeneralInformation/403183) |
5 | | -<!-- default badges end --> |
6 | | -<!-- default file list --> |
7 | | -*Files to look at*: |
8 | | - |
9 | | -* [Default.aspx](./CS/WebSite/Default.aspx) (VB: [Default.aspx](./VB/WebSite/Default.aspx)) |
10 | | -* [Default.aspx.cs](./CS/WebSite/Default.aspx.cs) (VB: [Default.aspx.vb](./VB/WebSite/Default.aspx.vb)) |
11 | | -<!-- default file list end --> |
12 | | -# How to use ASPxGridLookup two-way bound to LinqServerModeDataSource in GridViewDataComboBoxColum |
| 1 | +# Grid View for ASP.NET Web Forms - How to edit grid data using a two-way data-bound grid lookup in dynamic item load mode |
13 | 2 | <!-- run online --> |
14 | 3 | **[[Run Online]](https://codecentral.devexpress.com/e3653/)** |
15 | 4 | <!-- run online end --> |
16 | 5 |
|
| 6 | +This example demonstrates how to add a grid lookup editor to a column edit item template, bind the editor to a large data source, and enable its dynamic item load mode. |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +Create a combo box column and specify its [EditItemTemplate](https://docs.devexpress.com/AspNet/DevExpress.Web.GridViewDataColumn.EditItemTemplate) property. Add a grid lookup control to the template, bind it to a [LinqServerModeDataSorce](https://docs.devexpress.com/AspNet/DevExpress.Data.Linq.LinqServerModeDataSource), and use the [Bind](https://learn.microsoft.com/en-us/previous-versions/aspnet/ms178366(v=vs.100)#using-the-bind-method) method to bind the control's `Value` property to the corresponding field in the main grid's data source. |
| 13 | + |
| 14 | +```aspx |
| 15 | +<dx:ASPxGridView ID="ASPxGridView1" runat="server" DataSourceID="SqlDataSource1" KeyFieldName="ProductID" |
| 16 | + AutoGenerateColumns="False" ClientIDMode="AutoID" > |
| 17 | + <Columns> |
| 18 | + <!-- ... --> |
| 19 | + <dx:GridViewDataComboBoxColumn FieldName="CategoryID" VisibleIndex="2"> |
| 20 | + <PropertiesComboBox TextField="CategoryName" ValueField="CategoryID" ValueType="System.String" |
| 21 | + IncrementalFilteringMode="Contains" EnableCallbackMode="true" CallbackPageSize="7" |
| 22 | + OnItemRequestedByValue="ItemRequestedByValue" |
| 23 | + OnItemsRequestedByFilterCondition="ItemsRequestedByFilterCondition"> |
| 24 | + </PropertiesComboBox> |
| 25 | + <EditItemTemplate> |
| 26 | + <dx:ASPxGridLookup ID="ASPxGridLookup1" runat="server" KeyFieldName="CategoryID" |
| 27 | + AutoGenerateColumns="False" DataSourceID="LinqServerModeDataSource1" |
| 28 | + TextFormatString="{1}" Value='<%# Bind("CategoryID") %>' |
| 29 | + IncrementalFilteringMode="Contains"> |
| 30 | + <GridViewProperties> |
| 31 | + <SettingsBehavior AllowFocusedRow="True" AllowSelectSingleRowOnly="True" /> |
| 32 | + </GridViewProperties> |
| 33 | + <Columns> |
| 34 | + <!-- ... --> |
| 35 | + </Columns> |
| 36 | + </dx:ASPxGridLookup> |
| 37 | + </EditItemTemplate> |
| 38 | + </dx:GridViewDataComboBoxColumn> |
| 39 | + </Columns> |
| 40 | +</dx:ASPxGridView> |
| 41 | +``` |
17 | 42 |
|
18 | | -<p>This example demonstrates how to utilize the <strong>GridViewDataComboBoxColumn</strong> that retrieves "<strong>lookup</strong>" values via the <a href="http://documentation.devexpress.com/#AspNet/CustomDocument8196"><u>Dynamic List Population</u></a> mode (in a browse ASPxGridView mode).</p><p>The <strong>ASPxGridLookup</strong>, which is defined within the <strong>column's EditItemTemplate</strong>, is used as the column's editor and bound with a separate <strong>LinqServerModeDataSource</strong> control via the<strong> two-way binding</strong> option. This approach is useful when ASPxGridLookup should be bound to a <strong>large data source</strong>.</p><p>To use the <strong>default ASPxComboBox editor</strong> (produced by the GridViewDataComboBoxColumn PropertiesComboBox), which operates in a "Dynamic List Population" mode, simply <strong>remove the column's EditItemTemplate</strong> (with the ASPxGridLookup control) definition.</p><p><strong>See also:</strong><br /> |
19 | | -<a href="http://documentation.devexpress.com/#AspNet/CustomDocument3726"><u>Server Mode Overview</u></a></p> |
| 43 | +Set the column's [EnableCallbackMode](https://docs.devexpress.com/AspNet/DevExpress.Web.ASPxAutoCompleteBoxBase.EnableCallbackMode) property to `true` to enable the [database server mode](https://docs.devexpress.com/AspNet/3787/components/data-editors/common-concepts/binding-to-data#binding-to-large-data-database-server-mode) and handle the following server-side events to dynamically load items in the grid lookup: |
20 | 44 |
|
21 | | -<br/> |
| 45 | +* [ASPxComboBox.ItemRequestedByValue](https://docs.devexpress.com/AspNet/DevExpress.Web.ASPxComboBox.ItemRequestedByValue) event obtains selected items specified by their values. |
| 46 | +* [ASPxComboBox.ItemsRequestedByFilterCondition](https://docs.devexpress.com/AspNet/DevExpress.Web.ASPxComboBox.ItemsRequestedByFilterCondition) event selects items by filter conditions. |
| 47 | + |
| 48 | +```cs |
| 49 | +public void ItemRequestedByValue(object source, DevExpress.Web.ListEditItemRequestedByValueEventArgs e){ |
| 50 | + int value = 0; |
| 51 | + if(e.Value == null || !Int32.TryParse(e.Value.ToString(), out value)) |
| 52 | + return; |
| 53 | + ASPxComboBox comboBox = (ASPxComboBox)source; |
| 54 | + DataClassesDataContext dataContext = new DataClassesDataContext(); |
| 55 | + int id = Int32.Parse(e.Value.ToString()); |
| 56 | + var query = from category in dataContext.Categories |
| 57 | + where category.CategoryID == id |
| 58 | + select category; |
| 59 | + var count = query.Count(); |
| 60 | + comboBox.DataSource = query; |
| 61 | + comboBox.DataBind(); |
| 62 | +} |
| 63 | + |
| 64 | +public void ItemsRequestedByFilterCondition(object source, DevExpress.Web.ListEditItemsRequestedByFilterConditionEventArgs e){ |
| 65 | + ASPxComboBox comboBox = (ASPxComboBox)source; |
| 66 | + var skip = e.BeginIndex; |
| 67 | + var take = e.EndIndex - e.BeginIndex + 1; |
| 68 | + DataClassesDataContext dataContext = new DataClassesDataContext(); |
| 69 | + var queryStartWidth = |
| 70 | + (from category in dataContext.Categories |
| 71 | + where category.CategoryName.StartsWith(e.Filter) |
| 72 | + orderby category.CategoryName |
| 73 | + select category).Skip(skip).Take(take); |
| 74 | + comboBox.DataSource = queryStartWidth; |
| 75 | + comboBox.DataBind(); |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +## Files to Review |
| 80 | + |
| 81 | +* [Default.aspx](./CS/WebSite/Default.aspx) (VB: [Default.aspx](./VB/WebSite/Default.aspx)) |
| 82 | +* [Default.aspx.cs](./CS/WebSite/Default.aspx.cs) (VB: [Default.aspx.vb](./VB/WebSite/Default.aspx.vb)) |
22 | 83 |
|
| 84 | +## Documentation |
23 | 85 |
|
| 86 | +* [Item Load Modes](https://docs.devexpress.com/AspNet/8205/components/data-editors/aspxcombobox/concepts/item-loading-modes) |
| 87 | +* [Binding to Large Data (Database Server Mode)](https://docs.devexpress.com/AspNet/3787/components/data-editors/common-concepts/binding-to-data#binding-to-large-data-database-server-mode) |
| 88 | + *[Bind Grid View to Large Data (XPO)](https://docs.devexpress.com/AspNet/3726/components/grid-view/concepts/bind-to-data/binding-to-large-data-database-server-mode/data-binding-to-large-data-via-xpo) |
0 commit comments