Databinding Using the DetailsView Control
The DetialsView control lets us work with and manipulate data from the SQL database by using and configuring a simple control. In order to follow this tutorial you must have an SQL database installed on visual studio in order to bind the control to it. You can download and use the sample database tutorial in order to follow along as well.
Open the website project in visual studio and right click on the name of the website in the solution explorer. Select Add New Item.
When the Installed Templates list opens, select a Web Form then name it and click Add. If you are planning on using this control in an existing project you can skip the previous steps. Switch to design view.
In the Toolbox under the data menu, click and drag a DetailsView control onto the page.
In the DetailsView Tasks menu select the data source you want to bind to from the drop down menu (If you are using the sample database provided, the data source will be the default SqlDataSource1). See the image below.
When the Data Connection Wizard opens, Select ConnectionString from the dropdown menu and click next.
When the next window opens (Configure the Select Statement) make sure the Asterisk on the top of the checklist box menu is selected (this selects all items in the list). See image below. The columns list lets you select which items from the database table you want to incorporate into the control.
We moved our web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.
In the same window click the advanced button on the right side of the menu. See image below. The Generation options menu lets you create statements on your control that let the user insert, edit and delete content in the SQL database.
Make sure the top box is checked and the bottom box is unchecked and then click Ok.
Select next in the Configure the Select Statement menu.
The last menu in the wizard to appear is the Test Query menu. You can test your SQL connection by clicking on the Test Query button. The table data you are binding the control to will appear in the preview window if the connection is successful. See image below.
Select the DetailsView Tasks menu again and notice that now there are some additional selections. These selections let you customize the control to enable paging, inserting, editing, and deleting of the database information.
Save your work then run or debug the application. You now have a functional DetailsView control you can use to manage the data from the SQL database on your webpages.
Yes, it is possible to find a good web host. Sometimes it takes a while to find one you are comfortable with. After trying several, we went with Server Intellect and have been very happy thus far. They are by far the most professional, customer service friendly and technically knowledgeable host we’ve found so far.
A Few Last Words…Learning how to control and manipulate databases is easy with ASP.NET and we intend to be there ever step of the way to help! Thank you for being a valued reader and join us next time for additional database tutorials!