Skip to main content

Practical-19

Display data into GridView control

In this practical, we will learn how to display data into a GridView control in ASP.NET.

Step 1: Create a new ASP.NET Web Application project

  1. Open Visual Studio and create a new ASP.NET Web Application project.
  2. Choose the Empty template and click OK.

Step 2: Add a GridView control to the web form

  1. Open the default.aspx file in the Solution Explorer.
  2. Switch to the Design view.
  3. Drag and drop a GridView control from the Toolbox onto the web form.

Step 3: Configure the GridView control

  1. Select the GridView control on the web form.
  2. In the Properties window, set the DataSource property to the data source from which you want to display data.
  3. Set the AutoGenerateColumns property to true to automatically generate columns for the GridView.
  4. Optionally, you can customize the appearance and behavior of the GridView by modifying other properties such as PageSize, AllowSorting, etc.

Step 4: Bind data to the GridView control

  1. In the code-behind file (default.aspx.cs), write the necessary code to fetch data from the data source.
  2. Use the GridView's DataBind() method to bind the data to the GridView control.

Step 5: Run the application

  1. Press F5 or click the Start Debugging button to run the application.
  2. The web form will display the data from the data source in the GridView control.

That's it! You have successfully displayed data into a GridView control in ASP.NET.

Make sure to save your changes and submit this practical in your notebook.