Databinding Using the FormView Control in ASP.NET

In this tutorial we will be learning how to create a FormView control and binding it to a pre-existing database table.

The FormView 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 in 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.


The Concept…

Open the provided 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 FormView Control onto the page.

In the FormView 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.

Need help with cloud hosting? Try Server Intellect. We used them for our cloud hosting services and we are very happy with the results!


When the Data Connection Wizard opens,
Select ConnectionString from the dropdown menu and then 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). The columns list lets you select which items from the database table you want to incorporate into the control.

In the same window click the Advanced Button on the right side of the menu. The Generation Options menu lets you create statements within your control that allows the user insert, edit and delete content inside the SQL database.

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.


Make sure the top box is checked and the bottom box is unchecked and then click Ok. SelectNext 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.

Click Finish. Select the FormView 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 FormView control you can use to manage the data from the SQL database on your webpages.

Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.

A Few Last Words…

Learning how to control and manipulate databases in ASP.NET is easy and we intend to be there to help you with every step you take! Thank you for being a valued reader and join us next time for additional database tutorials!

FormView.zip


0 komentar:

Posting Komentar