Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Сreate a data table and grid control at runtime and use the grid's server-side events to update the data table.

License

DevExpress-Examples/asp-net-web-forms-grid-edit-data-table-stored-in-viewstate

Repository files navigation

Grid View for ASP.NET Web Forms - How to edit a data table stored in a ViewState

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

Overview

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();
}

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Сreate a data table and grid control at runtime and use the grid's server-side events to update the data table.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

AltStyle によって変換されたページ (->オリジナル) /