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)
In the previous article ASP. NET: I like Web Form, but I like drag controls (2). Some comments mentioned that how did Lao Zhao run with steamed stuffed bun dumplings? Let's take a closer look. The tables listed in this way do have some problems. company_id is designed as a foreign key. If you directly list this table, company_id is incomprehensible.
Id |
Name |
Company_id |
Image |
1 |
Steamed Stuffed bun |
3 |
[Bin] |
2 |
Steamed dumplings |
3 |
[Bin] |
3 |
Talent |
1 |
[Bin] |
4 |
MVP |
1 |
[Bin] |
5 |
Window 7 |
2 |
[Bin] |
Let's move forward and recall the first ASP. NET series in this series: Like Web Form, or drag controls (1)
There seems to be another table:
Company
Id |
Name |
1 |
Blog |
2 |
Microsoft |
3 |
Sub-shop downstairs |
Good, Lao Zhao and steamed dumplings are not a place. Our users prefer to see the following table:
Id |
Name |
Company_name |
Image |
1 |
Steamed Stuffed bun |
Sub-shop downstairs |
[Bin] |
2 |
Steamed dumplings |
Sub-shop downstairs |
[Bin] |
3 |
Talent |
Blog |
[Bin] |
4 |
MVP |
Blog |
[Bin] |
5 |
Window 7 |
Microsoft |
[Bin] |
Such a data table is much clearer.
Speaking of implementation, your first thought may be C # querying, but the database provides us with a better method: View.
We need to create a view in the database so that we can obtain correct semantics and potential underlying optimization.
Shows how to create a view:
When using the GridView for display, we do not need any special processing. We only need to query the view as a normal table.
Okay, it's good to use the GridView to display this time. Next let's take a look at the problem with this form:
Our submission form looks very earthy. You need to manually enter the company id!
As mentioned above, users cannot see the id, let alone input it! Therefore, a more friendly input method should be provided. So we thought, since the number of companies is limited, it is a good idea to make a drop-down list. We only need to change TextBox to DropDownList In the insert template, change its data source to the data source of the Company table (note that each DropDownList has its own data source), and then configure data binding in the following way:
Okay, that's easy. Our company id field can be selected from dropdownlist.
Don't be busy. We have another data item: id. In fact, we want this id to be automatically generated instead of submitted by users. This solution has nothing to do with ASP. NET. You only need to set the id in the database to an auto-increment field, as shown in the figure below:
Then, we need to update the data source and FormView template, which is easy to say.
Now we have a fully functional form. Let's further raise a requirement and add a field to the data table: add time
Id |
Name |
Company_id |
Image |
Adddate |
1 |
Steamed Stuffed bun |
3 |
[Bin] |
9-12-14 |
2 |
Steamed dumplings |
3 |
[Bin] |
9-12-14 |
3 |
Talent |
1 |
[Bin] |
9-12-14 |
4 |
MVP |
1 |
[Bin] |
9-12-14 |
5 |
Window 7 |
2 |
[Bin] |
9-12-14 |
This addition time does not require users to input data by themselves. We hope that the time will be used each time data is inserted, and we must avoid malicious user changes.
In fact, we only need to Insert the SQL statement, and then reconfigure the FormView data source to change the Insert statement:
Insert into [commodity] ([name], [company_id], [image], [addtime]) VALUES (@ name, @ company_id, @ image, CURRENT_TIMESTAMP)
Insert a new data record and try to run it as expected. T-SQL is actually a very powerful language, it is even Turing complete, we in the storage of a lot of logical operations and transformations can be done through T-SQL, flexible Use of T-SQL can save a lot of effort in C.
Next notice:
We will focus on the integration with clients. In fact, as long as the principles are observed during use, ASP. NET can generate high-quality HTML code.