After data is bound to a DataGrid (automatically creating columns), you do not need to re-bind it when the page is sent back (caused by a non-grid event, the DataGrid still displays the data before sending back. However, when the DataGrid is in "edit" mode, it needs to be re-bound. Otherwise, all the edited rows are null. If we cancel editing (and re-bind), the edited value will be overwritten by the original value in the data source.
So why does it need to be rebound? When "edit" is not used, data can be displayed back and forth. Why does grid not know the original data when it is edited? You need to bind the data to it again.
This can be understood from the Use process of the itemtemplate. The template column can be flexibly customized for editing (textbox may be used) and normal display (literal) statuses to control grid display more flexibly, data in each State can be flexibly presented. Therefore, when switching, the grid
PossibleBecause you do not know how to display data, you simply do not display data. However, the opposite is true. When the grid does not use the template column to specify the display control in the editing state, the default value is textbox. Since Bill knows this, I also know why the returned data (the original grid data) is not automatically assigned a value? Again and again, let everyone re-bind?
From another perspective, if every column of the grid is dynamically created using the template column, its normal display status is the itemtemplate of the template column, data is displayed in textbox instead of literal. When the entire grid is displayed, each cell can be directly edited. Then, if the page is not re-bound after the page is sent back, the edited Value
NoOriginal Value in the data source
OverwriteThis is understandable. If you re-bind
,Do you still remember "Overwrite" in the first section?
This problem may be caused by the fact that page sending back contains dynamically created pages and related data. However, after sending the API back, Asp.net re-creates the page based on the original page, and fills in the stored data again based on the returned page data. So what is this mechanism?
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service