The server dynamically loads the DataGrid control and sets its attributes.
Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
DataGrid plays an important role in Asp.net programming. It is almost indispensable to present large batches of data in a browser. The commonly used methods for setting the DataGrid attribute are implemented by Asp statements at the front end, which is obviously not suitable for the dynamic loading of the DataGrid. It is very important to implement the foreground functions through the C # code at the back end, the following describes how to set an instance.
Like other methods for dynamically loading Server controls, to present a DataGrid on a client browser, you must have a Panel Container Control to load it. The generation method is as follows: panel Panel1 = new Panel ();
If necessary, you can set other attributes of the Panel. For details, see the appendix.
If the Panel size does not change with the DataGrid size, add the following code:
Panel1.Style ["OVERFLOW"] = "auto ";
Create a DataGrid control: DataGrid myDataGrid = new DataGrid ();
If the data in each column is not automatically loaded but manually bound, add the following code:
MyDataGrid. AutoGenerateColumns = false;
Use the following statement to set the title of each column, bind the byte, and add it to the myDataGrid control:
BoundColumn s1 = new BoundColumn ();
S1.DataField = "EmployeeID ";
S1.HeaderText = "employee ID ";
MyDataGrid. Columns. Add (s1 );
Set the position of myDataGrid using the following code:
MyDataGrid. Style ["Position"] = "Absolute ";
MyDataGrid. Style ["Left"] = "0px ";
MyDataGrid. Style ["Top"] = "0px ";
The Left and Top attributes are relative to panel1.
Because the DataGrid is rich in performance, its attribute settings are very complicated, including the small steps such as the background color and font size can be set according to the user's definition, for detailed attribute setting code, see the appendix. It is worth noting that CellPadding is used to obtain or set the space between the cell content and the cell border; CellSpacing is used to obtain or set the space between cells; selectedItemStyle is used to obtain the style attributes of the selected items. ItemStyle is used to obtain the style attributes of various items in the MyDataGrid control. HeaderStyle is used to obtain the style attributes of the title part of the MyDataGrid control; the style attribute ensures that the Chinese character of the Header title is displayed in one row.
Use the following code to add the MyDataGrid control to Panel1:
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.