The server dynamically loads the DataGrid control and sets its attributes.

Source: Internet
Author: User
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:
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.