This example demonstrates how to create a data table and grid control at runtime and use the grid's server-side events to update the data table.
Edit a data table stored in ViewState
Create a data table at runtime and save it to a ViewState.
private DataTable CustomDataSourse { get { if (dataTable != null) return dataTable; dataTable = ViewState["CustomTable"] as DataTable; if (dataTable != null) return dataTable; dataTable = new DataTable("CustomDTable"); dataTable.Columns.Add("Id", typeof(Int32)); dataTable.PrimaryKey = new DataColumn[] { dataTable.Columns[0] }; dataTable.Columns.Add("Data", typeof(string)); // ... ViewState["CustomTable"] = dataTable; return dataTable; } }
Create a grid control at runtime and set its EnableCallbacks property to false to enable postback mode. This mode allows you to store data in a ViewState.
private void CreateGrid() { ASPxGridView grid = new ASPxGridView(); grid.ID = "grid"; this.Form.Controls.Add(grid); grid.EnableCallBacks = false; grid.KeyFieldName = "Id"; // ... }
Update the data table in the corresponding grid's event handlers and bind the grid to the updated data table.
private void UpdateData(ASPxGridView g) { ViewState["CustomTable"] = dataTable; g.DataBind(); }
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
- Grid View for ASP.NET Web Forms - How to edit a data table stored in a session
- Grid View for ASP.NET Web Forms - How to edit an in-memory data set with a master-detail relationship
(you will be redirected to DevExpress.com to submit your response)