ASP. NET: Like Web Form, or drag controls (1)

Source: Internet
Author: User
Document directory
  •  

ASP. NET: Like Web Form, or drag controls (1)
ASP. NET: Like Web Form, or drag controls (2)
ASP. NET: Like Web Form, or drag controls (3)
ASP. NET: Like Web Form, or drag controls (4)
ASP. NET: Like Web Form, or drag controls (5)

 

Trust all ASP. NET programmers are no stranger to the GridView, but FormView is rarely used. Here we will start some beginners. NET friends introduce some tips about FormView, it is worth noting that, these skills are not suitable for large and medium-sized websites (suitable for dealing with jobs like XXX systems ......). If you want a three-tier structure, ORM, AJAX, or something, you can ignore this article. To put it bluntly, it is dedicated to laziness.

 

For convenience, we can first YY a simple database, assuming there are two table companies and products

The product has three fieldsProduct id, product name, and production company idTo facilitate expansion and modification, we use the company id instead of the name of the production company. Of course, it is best to add a foreign key constraint for this company id. This database design is very common. It looks as follows:

Commodity

Id Name Company_id
1 Steamed Stuffed bun 3
2 Steamed dumplings 3
3 Talent 1
4 MVP 1
5 Windows 7 2

 

The company has two fieldsCompany id and company nameIt looks like the following:

Company

Id Name
1 Blog
2 Microsoft
3 Sub-shop downstairs

 

OK. Now that we have a database, we can get to the topic. What is FormView used? You can add, delete, modify, and query database operations. FormView is suitable for adding, modifying, and querying database operations.

 

Suppose we want to add a record to the company table of this database, we can implement it using FormView:

Drag a FormView, select a data source from the arrow, and select a new Data source:

 

The Data Source Creation wizard is automatically displayed. DataBase is generally selected here. Of course, some students prefer to pursue a more fashionable LINQ data source and will not discuss it here.

After the Data source is created, we need a Data Connection. Because the databases used by everyone are different, we will not discuss it in detail. For the time being, I think the ConnectionString has been set up, and we can just click Next.

Then we can select data tables and columns. Here we can select both id and name.

But don't rush to next. You need to click "Advanced" first and then select the two options. If the options are gray, the primary key of the database must be faulty.

 

Then click next and finish.

 

In this way, we have a FormView bound to the data source and run the following result:

 

As you can see, FormView is used to display the first query result, but if so, FormView has no meaning.

Next, let's take a look at the practical and useful usage of FormView.

Now let's modify the Default attribute of FormView.

Run it again. You can see that a form that inserts data into Company has been generated!

This is nothing for a Company table, but for tables with many fields, simple configuration can save a lot of work.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.