Asp – How to preserve value of dynamic created gridview column

asp.net

I have created all gridview column dynamically and column also exists checkbox. Issue with gridview is its not preserving dynamic created column value. For example if i have selected few row through checkbox column and clicked on button to get all selected row id. As page post back the grid becomes empty with no data value.

Any help will be highly appreciated.

Thanks,
Alvin

Best Answer

This is probably caused by when you're creating the dynamic column.

If the column is created in the Page_Load event, or later in the page event process, then ViewState will not be able to populate your columns on a PostBack.

If possible, try creating your dynamic columns in the Page_Init event. This will allow ViewState to load the columns properly.

Related Topic