Skip to content

Commit d6c3642

Browse files
authored
update example (#1)
* update description * Update Readme.md
1 parent aca4c76 commit d6c3642

File tree

3 files changed

+83
-17
lines changed

3 files changed

+83
-17
lines changed
71.2 KB
Loading

Readme.md

Lines changed: 80 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,88 @@
1-
<!-- default badges list -->
2-
![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/128543458/15.1.3%2B)
3-
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/E3653)
4-
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](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
132
<!-- run online -->
143
**[[Run Online]](https://codecentral.devexpress.com/e3653/)**
154
<!-- run online end -->
165

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+
![Grid Lookup in dynamic item load](BindGridLookupToLargeDataSource.png)
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+
```
1742

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:
2044

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))
2283

84+
## Documentation
2385

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)

config.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"runOnWeb": true,
3-
"autoGenerateVb": true
4-
}
3+
"autoGenerateVb": true,
4+
"useLegacyVbConverter": true
5+
}

0 commit comments

Comments
 (0)