Grid View for ASP.NET Web Forms - How to bind a Combo Box column to data based on the row index in batch edit mode
This example demonstrates how to populate a GridViewDataComboBoxColumn's cell editors at runtime in batch edit mode.
In batch edit mode, the Grid View does not send requests to the server when a cell editor is activated. Therefore, it is not possible to use the CellEditorInitialize event handler on the server to populate a combo box in each row.
To overcome this limitation, use the combo box editor's callback to populate the editor with items.
-
Handle the grid's CellEditorInitialize event. In the event handler, assign a new handler to the combo box cell editor's Callback event:
protected void Grid_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e) { if (e.Column.FieldName == "C3") { ASPxComboBox combo = e.Editor as ASPxComboBox; combo.Callback += combo_Callback; } }
-
Call the combo box editor's PerformCallback method from the client ASPxClientGridView.BatchEditStartEditing event handler. Pass the current row's visible index as the callback parameter:
<dx:ASPxGridView ID="Grid" runat="server" KeyFieldName="ID" ... > ... <ClientSideEvents BatchEditStartEditing="OnBatchEditStartEditing" /> </dx:ASPxGridView>
function OnBatchEditStartEditing(s, e) { cmb.PerformCallback(); }
-
Add items to the combo box in the Callback event handler. You can get the current row index from
e.Parameter
.void combo_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e) { ASPxComboBox combo = sender as ASPxComboBox; for (int i = 0; i < 10; i++) { combo.Items.Add(string.Format("Row_{0} Item_{1}", e.Parameter, i), i); } }
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
- Grid View for ASP.NET Web Forms - How to bind the GridViewDataComboBoxColumn edit form editor at runtime
- Grid View for ASP.NET Web Forms - How to cache data on the client
(you will be redirected to DevExpress.com to submit your response)