Skip to main content

Practical-20

Display data into DetailView Control

In this practical, we will learn how to display data into a DetailView 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 DetailView 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 DetailView control from the Toolbox onto the web form.

Step 3: Configure the DetailView control

  1. Select the DetailView 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 AutoGenerateRows property to true to automatically generate rows for the DetailView.
  4. Optionally, you can customize the appearance and behavior of the DetailView by modifying other properties such as Mode, DefaultMode, etc.

Step 4: Bind data to the DetailView control

  1. In the code-behind file (default.aspx.cs), write the necessary code to fetch data from the data source.
  2. Use the DetailView's DataBind() method to bind the data to the DetailView 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 DetailView control.

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

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