Get the App
SLTechnology News&Howtos  ›  Development  › 

Hidden trouble Analysis of ASP.NET Virtual Host in creating data Source

Shulou Source: shulou.com Published: 2022-06-02 22:25:49 09月30日 Update

This article shows you the hidden trouble analysis of ASP.NET virtual host when creating data source, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

What are the hidden dangers of ASP.NET virtual hosts when creating data sources? First, let's look at the code that creates the data source (the code is in the listdrivers.aspx.cs file):

/ / return a data view in the form of a collection DataView ICollection CreateDataSource () {/ / define a data table in memory DataTable DataTable dt = new DataTable (); / / define a row of data in DataTable DataRow DataRow dr; / * add a column to DataTable, format: DataColumn ("Column", type) Column is the name of the data column, type is the data type of the data column * / dt.Columns.Add ("ID", typeof (Int32)) Dt.Columns.Add (new DataColumn ("drivers", typeof (string)); dt.Columns.Add (new DataColumn ("detail", typeof (string); / / use the for loop to add the name of the logical drive as a row to the data table DataTable for (int I = 0; I < nNumOfDrives; iDrive +) {/ / define the new line dr = dt.NewRow () / assign each column in a pair of rows, note that dr [0] = I corresponding to the row of DataTable defined above; / / cycle generated sequence number dr [1] = achDrives [I] .ToString (); / / name of logical drive dr [2] = "View details"; / / add row dt.Rows.Add (dr) to DataTable;} / generate custom view DataView DataView dv = new DataView (dt) based on the resulting DataTable / / return the resulting view DataView return dv;}

In this way, we get a data View DataView that contains all the data we need. We just need to bind this data View to DataGrid in the Page_Load method of this aspx page.

The data binding code of the ASP.NET virtual host when creating the data source (the code is in the listdrivers.aspx.cs file):

/ * set the data source DataSource of DataGrid to the data view DataView * / DriversGrid.DataSource = CreateDataSource () obtained from the CreateDataSource () method; / / bind this DataGrid to DriversGrid.DataBind ()

Through the main methods described above, we have achieved the function of obtaining system information and displaying all logical drive names, and you can go to the next program listdir.aspx that displays directory and file names through the corresponding link to display all directories and files under the logical drive.

The above is the hidden trouble analysis of the ASP.NET virtual host when creating the data source. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Data data source view host virtual host code file method logic driver driver hidden danger name analysis above content form skill datasheet directory Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Apple Xiaomi Shulou Information Linux