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.
Loading...
Related Quiz
- Parameterized queries help prevent _______ attacks by sanitizing user input.
- Which of the following is true about ADO.NET Entity Framework?
- Data readers provide ___________ access to data, which can be beneficial for performance when reading large datasets.
- In LINQ to Entities, the ___________ operator is used to combine two or more sequences into a single result.
- Which ADO.NET data reader is used specifically for working with SQL Server databases?