Currently, we work with a boss. Considering the network factors, we decided to use Microsoft Visual Studio 2005 and Microsoft SQL Server 2005 for project development. My boss has defined a short time. I have to deal with it in a month, and I am almost alone. Why.
I like Microsoft's development tools.
NET 2.0 is about 70% less than the previous version. Code Well, at the beginning, the code was particularly Doha because the thinking was fixed at 1.0. Fortunately, I was able to see 2.0 of the power of this project. Coupled with the Free ASP. NET Ajax Tool provided by Microsoft, I felt like it was awesome to develop!
Today we use two data controls: gridview and detailsview. We didn't know at first that detailsview cannot be directly added for verification (don't laugh ), after you have added the objectdatasource control and added the insert, update, delete, select, and other implementation methods, you have a special sense of accomplishment! However, the headache also arises. :( When I add data to detailsview, if I do not input any error, I cannot find any place to add the verification control. Therefore, Baidu and Google search solutions do not have a good solution, add a lot of code.
At this time, I think Microsoft should not be doing so badly. There is always a way to deal with it. So I started from the objectdatasource control and the detailsview control and tried to solve the problem by finding out their attributes and events. Finally, I found an event on objectdatasource: inserting.
We can add a processing under this method to implement verification. The following is an example:
1 Protected Void Performance1_inserting ( Object Sender, object‑cemethodeventargs E) {
2 String Username = "" ;
3 // Assume that username is the first input parameter of detailsview.
4 If (E. inputparameters [ 0 ] ! = Null )
5 Username = E. inputparameters [ 0 ]. Tostring (). Trim ();
6
7 If (Username = "" ) {
8 // Showerror is a custom input error method.
9 Showerror ( " The language ID or description cannot be blank! " );
10 E. Cancel = True ;
11 }
12 }
The premise is that the data source of the detailsview control must be specified as an objectdatasource control or another datasource control.
(You can put the gridview and detailsview in ASP: updatepanel to avoid refreshing too much)
I think this is the easiest way to verify it. I hope that all my friends who have encountered the same problems will not take a detour.