Scenario: You are developing a web application and need to populate a DropDownList control with a list of product categories from a database. What steps would you take to achieve this?

  • Use ADO.NET to retrieve data from the database and then loop through the results to populate the DropDownList control.
  • Use Entity Framework to query the database and bind the results directly to the DropDownList control.
  • Use LINQ to SQL to query the database and bind the results directly to the DropDownList control.
  • Use a data source control like SqlDataSource to connect to the database and bind it to the DropDownList control.
Option 4 is the correct approach. SqlDataSource provides an efficient and easy way to connect to a database and bind data to a DropDownList control in ASP.NET applications. By configuring the SqlDataSource control with the appropriate SQL query or stored procedure, you can populate the DropDownList with product categories from the database. This approach also helps in maintaining separation of concerns by keeping data access logic separate from UI code.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *