How to Add DataGridView to a Dynamic Table

The .NET "DataGridView" control displays data on your Web pages. The "DataTable" control contains the data you use in the DataGridView. You dynamically bind these two controls together to display records on the Web page. You must first create the table, then add the DataGridView to the table. .NET automatically parses the data and displays the records in a list of rows and columns.

Instructions

    • 1

      Open the Visual Studio software and open your Web project. Double-click the .NET code file you want to use to add the grid and table.

    • 2

      Create the DataTable control and fill it with data. The following code dynamically creates the table:

      DataTable table = new DataTable();
      DataRow dr = null;
      dr[0] = "Joe";
      dr[1] = "Smith";
      table.Row.Add(dr);

      The code above creates a table with one row, and the row contains a user's first and last name.

    • 3

      Add the DataGridView to the table. You link the two controls with the "DataSource" property. The following code adds the grid to the table:

      DataGridView.DataSource = table;

Related Searches:

References

Comments

Related Ads

Featured