Use of aspxgridview Control

Source: Internet
Author: User

1. Data Update Error
Use Aspxgridview Control Click Edit to edit a row. Update and cancel are displayed. After the data is edited, click Update. An error occurs: at the bottom of the row being edited, a sweaty background is highlighted in red, indicating that the specified method is not supported. The specified method is not supported.
Figure 1:

The solution is to use the data source control to load data and specify Aspxgridview Control OfDatasourceid is equal to the ID of the data source control and specifiesKeyfieldname. I learned this only after reading the official demo. I used to load data using the interface provided by the data access layer of our project. aspx. the CS file is bound to it. The reason for updating data is as follows: Aspxgridview Control Only displays data, but there is no data source after the web page is loaded. Therefore, you must use the data source control to save the data for update, the data source control is used to update data. I hope you can give us some advice on the unreasonable explanations.
There are many data source controls. Here I useObjectdatasource, because our project already has a data access layer, and no other data source controls are required to access the database. Create a folder under this web projectApp_code , In App_code Create a New Class ABC, define the namespace as demo, The namespace of the using data access layer, add a method loaddata, return the value of the datatable type, the method parameter is random, load the data returned in this method; add a method updatedata with at least one parameter, that is, some ID columns to be passed to the stored procedure and the values to be modified (these parameters must be in Objectdatasource Of The updateparameters attribute is added, and their names are the same as those of these parameter names.TheColumnsIf you do not want to display columns, you can setVisible = "false" ), So we certainly need to modify some values, or else we don't need to update, there is no need to return values, the method calls the data access layer method to modify data.
Then setObjectdatasource ControlTypename = "demo. ABC ",Selectmethod= "Loaddata ",Updatemethod= "Updatedata" and addSelectparametersParameter Name and value. The parameter name must be the same as the parameter name in the loaddata function. The value can be a control attribute or a session variable. It can be set as needed, as shown in. Okay, this time there is no red word, and the data is successfully modified.

2. Set the display format and style
Figure 2:

This is his official demo. How did they make this view style? I spent some time learning it. We often see many fields to display, but due to the limitation of the page width, we cannot display too much information in one line, but we need to display it during editing, you may also need to edit and update it. to edit the style displayed during editing, perform the following settings:
A> Confirm the mode of settingsediting = editformanddisplayrow and editformcolumncount = 3. Set multiple rows in Image 2 to edit, instead of embedding them in one row in Figure 1. Each row shows three columns.
Figure 3:

B> Set attributes of each column, as shown in.
Visible indicates whether a field is visible in the non-editing state. It can be used to set some too long fields or secondary fields to be invisible.
The visible of editformsettings is used to set whether the field is visible in the editing state. Setting it to true enables the field that is too long or a secondary field to be displayed during editing.
Visibleindex refers to the position where the column is displayed in non-editing status. 0 indicates that the column is displayed in the first column, and so on.
The visibleindex of editformsettings is the same as the preceding one, but it is in the editing status.
With the above four attributes, you can set non-edit and edit statuses to display them in unnecessary order. There are two important attributes below:
The columnspan of editformsettings indicates the number of columns occupied by the column, which is equivalent TD tagColspan attributes
The rowspan of editformsettings indicates the number of rows occupied by the column, which is equivalent toRowspanAttribute

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.