C# • Implement Codeless Databinding

Listing 1. You can configure the SqlDataSource control solely by manipulating tags in the ASPX file. If you're not comfortable with the ASP.NET tags, then you can utilize the wizard in Visual Studio to achieve the same results. Utilizing Visual Studio to generate the databinding results in a true "hands-off" approach to databinding.

<asp:SqlDataSource ID="customersDataSource" 
        runat="server" 
                ConnectionString="<%$ 
                        ConnectionStrings:DatabaseConnection %>" 
                SelectCommand="SELECT * FROM Customers" />
                <asp:GridView ID="customersGridView" runat="server" 
                DataSourceID="customersDataSource" 
                AutoGenerateColumns="false">
                <Columns>
                        <asp:BoundField DataField="CompanyName" 
                                HeaderText="CompanyName"/>
                        <asp:BoundField DataField="ContactName" 
                                HeaderText="ContactName"/>
                        <asp:BoundField DataField="ContactTitle" 
                                HeaderText="ContactTitle"/>
                        <asp:BoundField DataField="Address" 
                                HeaderText="Address"/>
                        <asp:BoundField DataField="City" 
                                HeaderText="City"/>
                        <asp:BoundField DataField="Region" 
                                HeaderText="Region"/>
                        <asp:BoundField DataField="PostalCode" 
                                HeaderText="PostalCode"/>
                        <asp:BoundField DataField="Country" 
                                HeaderText="Country"/>
                        <asp:BoundField DataField="Phone" 
                                HeaderText="Phone"/>
                        <asp:BoundField DataField="Fax" 
                                HeaderText="Fax"/>   
                </Columns>
        </asp:GridView>