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
- Open Visual Studio and create a new ASP.NET Web Application project.
- Choose the Empty template and click OK.
Step 2: Add a GridView control to the web form
- Open the default.aspx file in the Solution Explorer.
- Switch to the Design view.
- Drag and drop a GridView control from the Toolbox onto the web form.
Step 3: Configure the GridView control
- Select the GridView control on the web form.
- In the Properties window, set the DataSource property to the data source from which you want to display data.
- Set the AutoGenerateColumns property to true to automatically generate columns for the GridView.
- 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
- In the code-behind file (default.aspx.cs), write the necessary code to fetch data from the data source.
- Use the GridView's DataBind() method to bind the data to the GridView control.
Step 5: Run the application
- Press F5 or click the Start Debugging button to run the application.
- 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.