Adding configuration properties to web parts
The web parts are configured by authorized users. You can use that as an opportunity and provide properties that can be set during the configuration time rather than hard coding in the code. In this recipe, we will learn how to add those configuration properties to the web parts.
In our first recipe, we had hard coded the database connection string. In this recipe, we will modify the web part to get the database connection string from the configuration property.
Getting ready
Since this recipe is a modification of the first recipe, you should complete that recipe successfully in order to follow this one.
How to do it...
If you have closed your Visual Studio IDE, launch it now as an administrator and open the solution file that we created in the first recipe.
Open the
EmployeeList.cs
and add a property calledDBConnectionString
with attributes as follows:Personalizable(PersonalizationScope.Shared), WebBrowsable, Category("DB Connection"), WebDisplayName...