|
1 | | -<!-- default badges list --> |
2 | | - |
3 | | -[](https://supportcenter.devexpress.com/ticket/details/E3653) |
4 | | -[](https://docs.devexpress.com/GeneralInformation/403183) |
5 | | -[](#does-this-example-address-your-development-requirementsobjectives) |
6 | | -<!-- default badges end --> |
7 | | -# 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 |
8 | | - |
9 | | -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. |
10 | | - |
11 | | - |
12 | | - |
13 | | -## Overview |
14 | | - |
15 | | -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. |
16 | | - |
17 | | -```aspx |
18 | | -<dx:ASPxGridView ID="ASPxGridView1" runat="server" DataSourceID="SqlDataSource1" KeyFieldName="ProductID" |
19 | | - AutoGenerateColumns="False" ClientIDMode="AutoID" > |
20 | | - <Columns> |
21 | | - <!-- ... --> |
22 | | - <dx:GridViewDataComboBoxColumn FieldName="CategoryID" VisibleIndex="2"> |
23 | | - <PropertiesComboBox TextField="CategoryName" ValueField="CategoryID" ValueType="System.String" |
24 | | - IncrementalFilteringMode="Contains" EnableCallbackMode="true" CallbackPageSize="7" |
25 | | - OnItemRequestedByValue="ItemRequestedByValue" |
26 | | - OnItemsRequestedByFilterCondition="ItemsRequestedByFilterCondition"> |
27 | | - </PropertiesComboBox> |
28 | | - <EditItemTemplate> |
29 | | - <dx:ASPxGridLookup ID="ASPxGridLookup1" runat="server" KeyFieldName="CategoryID" |
30 | | - AutoGenerateColumns="False" DataSourceID="LinqServerModeDataSource1" |
31 | | - TextFormatString="{1}" Value='<%# Bind("CategoryID") %>' |
32 | | - IncrementalFilteringMode="Contains"> |
33 | | - <GridViewProperties> |
34 | | - <SettingsBehavior AllowFocusedRow="True" AllowSelectSingleRowOnly="True" /> |
35 | | - </GridViewProperties> |
36 | | - <Columns> |
37 | | - <!-- ... --> |
38 | | - </Columns> |
39 | | - </dx:ASPxGridLookup> |
40 | | - </EditItemTemplate> |
41 | | - </dx:GridViewDataComboBoxColumn> |
42 | | - </Columns> |
43 | | -</dx:ASPxGridView> |
44 | | -``` |
45 | | - |
46 | | -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: |
47 | | - |
48 | | -* [ASPxComboBox.ItemRequestedByValue](https://docs.devexpress.com/AspNet/DevExpress.Web.ASPxComboBox.ItemRequestedByValue) event obtains selected items specified by their values. |
49 | | -* [ASPxComboBox.ItemsRequestedByFilterCondition](https://docs.devexpress.com/AspNet/DevExpress.Web.ASPxComboBox.ItemsRequestedByFilterCondition) event selects items by filter conditions. |
50 | | - |
51 | | -```cs |
52 | | -public void ItemRequestedByValue(object source, DevExpress.Web.ListEditItemRequestedByValueEventArgs e){ |
53 | | - int value = 0; |
54 | | - if(e.Value == null || !Int32.TryParse(e.Value.ToString(), out value)) |
55 | | - return; |
56 | | - ASPxComboBox comboBox = (ASPxComboBox)source; |
57 | | - DataClassesDataContext dataContext = new DataClassesDataContext(); |
58 | | - int id = Int32.Parse(e.Value.ToString()); |
59 | | - var query = from category in dataContext.Categories |
60 | | - where category.CategoryID == id |
61 | | - select category; |
62 | | - var count = query.Count(); |
63 | | - comboBox.DataSource = query; |
64 | | - comboBox.DataBind(); |
65 | | -} |
66 | | - |
67 | | -public void ItemsRequestedByFilterCondition(object source, DevExpress.Web.ListEditItemsRequestedByFilterConditionEventArgs e){ |
68 | | - ASPxComboBox comboBox = (ASPxComboBox)source; |
69 | | - var skip = e.BeginIndex; |
70 | | - var take = e.EndIndex - e.BeginIndex + 1; |
71 | | - DataClassesDataContext dataContext = new DataClassesDataContext(); |
72 | | - var queryStartWidth = |
73 | | - (from category in dataContext.Categories |
74 | | - where category.CategoryName.StartsWith(e.Filter) |
75 | | - orderby category.CategoryName |
76 | | - select category).Skip(skip).Take(take); |
77 | | - comboBox.DataSource = queryStartWidth; |
78 | | - comboBox.DataBind(); |
79 | | -} |
80 | | -``` |
81 | | - |
82 | | -## Files to Review |
83 | | - |
84 | | -* [Default.aspx](./CS/WebSite/Default.aspx) (VB: [Default.aspx](./VB/WebSite/Default.aspx)) |
85 | | -* [Default.aspx.cs](./CS/WebSite/Default.aspx.cs) (VB: [Default.aspx.vb](./VB/WebSite/Default.aspx.vb)) |
86 | | - |
87 | | -## Documentation |
88 | | - |
89 | | -* [Item Load Modes](https://docs.devexpress.com/AspNet/8205/components/data-editors/aspxcombobox/concepts/item-loading-modes) |
90 | | -* [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) |
91 | | - *[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) |
92 | | -<!-- feedback --> |
93 | | -## Does this example address your development requirements/objectives? |
94 | | - |
95 | | -[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=asp-net-web-forms-grid-edit-data-using-two-way-bound-lookup-in-dynamic-item-load-mode&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=asp-net-web-forms-grid-edit-data-using-two-way-bound-lookup-in-dynamic-item-load-mode&~~~was_helpful=no) |
96 | | - |
97 | | -(you will be redirected to DevExpress.com to submit your response) |
98 | | -<!-- feedback end --> |
| 1 | +<!-- default badges list --> |
| 2 | + |
| 3 | +[](https://supportcenter.devexpress.com/ticket/details/E3653) |
| 4 | +[](https://docs.devexpress.com/GeneralInformation/403183) |
| 5 | +[](#does-this-example-address-your-development-requirementsobjectives) |
| 6 | +<!-- default badges end --> |
| 7 | +# 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 |
| 8 | + |
| 9 | +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. |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +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. |
| 16 | + |
| 17 | +```aspx |
| 18 | +<dx:ASPxGridView ID="ASPxGridView1" runat="server" DataSourceID="SqlDataSource1" KeyFieldName="ProductID" |
| 19 | + AutoGenerateColumns="False" ClientIDMode="AutoID" > |
| 20 | + <Columns> |
| 21 | + <!-- ... --> |
| 22 | + <dx:GridViewDataComboBoxColumn FieldName="CategoryID" VisibleIndex="2"> |
| 23 | + <PropertiesComboBox TextField="CategoryName" ValueField="CategoryID" ValueType="System.String" |
| 24 | + IncrementalFilteringMode="Contains" EnableCallbackMode="true" CallbackPageSize="7" |
| 25 | + OnItemRequestedByValue="ItemRequestedByValue" |
| 26 | + OnItemsRequestedByFilterCondition="ItemsRequestedByFilterCondition"> |
| 27 | + </PropertiesComboBox> |
| 28 | + <EditItemTemplate> |
| 29 | + <dx:ASPxGridLookup ID="ASPxGridLookup1" runat="server" KeyFieldName="CategoryID" |
| 30 | + AutoGenerateColumns="False" DataSourceID="LinqServerModeDataSource1" |
| 31 | + TextFormatString="{1}" Value='<%# Bind("CategoryID") %>' |
| 32 | + IncrementalFilteringMode="Contains"> |
| 33 | + <GridViewProperties> |
| 34 | + <SettingsBehavior AllowFocusedRow="True" AllowSelectSingleRowOnly="True" /> |
| 35 | + </GridViewProperties> |
| 36 | + <Columns> |
| 37 | + <!-- ... --> |
| 38 | + </Columns> |
| 39 | + </dx:ASPxGridLookup> |
| 40 | + </EditItemTemplate> |
| 41 | + </dx:GridViewDataComboBoxColumn> |
| 42 | + </Columns> |
| 43 | +</dx:ASPxGridView> |
| 44 | +``` |
| 45 | + |
| 46 | +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: |
| 47 | + |
| 48 | +* [ASPxComboBox.ItemRequestedByValue](https://docs.devexpress.com/AspNet/DevExpress.Web.ASPxComboBox.ItemRequestedByValue) event obtains selected items specified by their values. |
| 49 | +* [ASPxComboBox.ItemsRequestedByFilterCondition](https://docs.devexpress.com/AspNet/DevExpress.Web.ASPxComboBox.ItemsRequestedByFilterCondition) event selects items by filter conditions. |
| 50 | + |
| 51 | +```cs |
| 52 | +public void ItemRequestedByValue(object source, DevExpress.Web.ListEditItemRequestedByValueEventArgs e){ |
| 53 | + int value = 0; |
| 54 | + if(e.Value == null || !Int32.TryParse(e.Value.ToString(), out value)) |
| 55 | + return; |
| 56 | + ASPxComboBox comboBox = (ASPxComboBox)source; |
| 57 | + DataClassesDataContext dataContext = new DataClassesDataContext(); |
| 58 | + int id = Int32.Parse(e.Value.ToString()); |
| 59 | + var query = from category in dataContext.Categories |
| 60 | + where category.CategoryID == id |
| 61 | + select category; |
| 62 | + var count = query.Count(); |
| 63 | + comboBox.DataSource = query; |
| 64 | + comboBox.DataBind(); |
| 65 | +} |
| 66 | + |
| 67 | +public void ItemsRequestedByFilterCondition(object source, DevExpress.Web.ListEditItemsRequestedByFilterConditionEventArgs e){ |
| 68 | + ASPxComboBox comboBox = (ASPxComboBox)source; |
| 69 | + var skip = e.BeginIndex; |
| 70 | + var take = e.EndIndex - e.BeginIndex + 1; |
| 71 | + DataClassesDataContext dataContext = new DataClassesDataContext(); |
| 72 | + var queryStartWidth = |
| 73 | + (from category in dataContext.Categories |
| 74 | + where category.CategoryName.StartsWith(e.Filter) |
| 75 | + orderby category.CategoryName |
| 76 | + select category).Skip(skip).Take(take); |
| 77 | + comboBox.DataSource = queryStartWidth; |
| 78 | + comboBox.DataBind(); |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +## Files to Review |
| 83 | + |
| 84 | +* [Default.aspx](./CS/WebSite/Default.aspx) (VB: [Default.aspx](./VB/WebSite/Default.aspx)) |
| 85 | +* [Default.aspx.cs](./CS/WebSite/Default.aspx.cs) (VB: [Default.aspx.vb](./VB/WebSite/Default.aspx.vb)) |
| 86 | + |
| 87 | +## Documentation |
| 88 | + |
| 89 | +* [Item Load Modes](https://docs.devexpress.com/AspNet/8205/components/data-editors/aspxcombobox/concepts/item-loading-modes) |
| 90 | +* [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) |
| 91 | + *[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) |
| 92 | +<!-- feedback --> |
| 93 | +## Does this example address your development requirements/objectives? |
| 94 | + |
| 95 | +[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=asp-net-web-forms-grid-edit-data-using-two-way-bound-lookup-in-dynamic-item-load-mode&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=asp-net-web-forms-grid-edit-data-using-two-way-bound-lookup-in-dynamic-item-load-mode&~~~was_helpful=no) |
| 96 | + |
| 97 | +(you will be redirected to DevExpress.com to submit your response) |
| 98 | +<!-- feedback end --> |
0 commit comments