The first task is to configure the data source for the
application. For this application I will be using SqlDataSource object, which
is introduced in .NET Framework 2.0. Simply drag and drop the SqlDataSource
object from the toolbox onto the designer. After that, you can follow a simple
wizard control to configure your data source.
Below is the HTML code generated by the SqlDataSource
control.
Listing 1 – SqlDataSource HTML
<asp:SqlDataSource ID="SqlDataSource1"
runat="server" ConnectionString="<%$
ConnectionStrings:TaskDatabaseConnectionString %>"
SelectCommand="SELECT [Name], [Address] FROM[Contacts]">
</asp:SqlDataSource>
Analysis
The SqlDataSource control simply selects [Name], [Address]
and [Contacts] from the Contacts table. Later in this article I will modify
the SqlDataSource control to be dependent on the selection from the
DropDownList control. Note that you must define the connection string in your
web.config (called TaskDatabaseConnectionString in this case) - the wizard will
prompt you for the connection string details if you haven't already defined a
connection string.