关于一次添加多张表单(或数据库记录)的Request用法
很多人都有一次在数据库写多条记录的经验,但是在Asp.Net的页面是如何体现的。不知大家是如何实现的,本人用Request对象加Javascript实现了一下。
先给大家贴贴我的页面:
1. 先看看最初始的情况
2. 看看点击这个Button后有什么产生
这样的javascript应该很好实现的,下面贴代码:


1 var customerNum = 1;
2 function AddEndCustomer()
3 {
4 customerNum = customerNum + 1;
5 var targetDivHtml = "";
6 targetDivHtml += "<table id=table_" + customerNum.toString() + " cellpadding=0px cellspacing=0px border=1px style=width:100%>";
7 targetDivHtml += "<tr><td colspan=4 style='font-size:15px'>End Customer(" + customerNum.toString() + ")</td></tr>"
8 targetDivHtml += "<tr>";
9 targetDivHtml += "<td class=tdField>Company Name:</td>";
10 targetDivHtml += "<td> <input type=text name=txtCompanyName /></td>";
11 targetDivHtml += "<td class=tdField>Individual Name:</td>";
12 targetDivHtml += "<td><input type=text name=txtIndividualName /></td>";
13 targetDivHtml += "</tr>";
14 targetDivHtml += "<tr>";
15 targetDivHtml += "<td class=tdField>Street Address(if know):</td>";
16 targetDivHtml += "<td colspan=3><input type=text name=txtStreet style=width:60% /></td>"
17 targetDivHtml += "</tr>";
18 targetDivHtml += "<tr>";
19 targetDivHtml += "<td class=tdField>City:</td>";
20 targetDivHtml += "<td><input type=text name=txtCity /></td>";
21 targetDivHtml += "<td class=tdField> State/Country:</td>";
22 targetDivHtml += "<td><input type=text name=txtState /></td>";
23 targetDivHtml += "</tr>";
24 targetDivHtml += "<tr>";
25 targetDivHtml += "<td class=tdField> Zip/Postal Code:</td>";
26 targetDivHtml += "<td><input type=text name=txtZip /></td>";
27 targetDivHtml += "<td class=tdField> Phone Number:</td>";
28 targetDivHtml += "<td><input type=text name=txtPhone /> </td>";
29 targetDivHtml += "</tr>";
30 targetDivHtml += "<tr>";
31 targetDivHtml += "<td class=tdField>E-mail:</td>";
32 targetDivHtml += "<td><input type=text name=txtEmail /></td>";
33 targetDivHtml += "<td class=tdField> EAU:</td>";
34 targetDivHtml += "<td><input type=text name=txtEAU /></td>";
35 targetDivHtml += "</tr>";
36 targetDivHtml += "<tr>";
37 targetDivHtml += "<td class=tdField> Date Of Production Begin:</td>";
38 targetDivHtml += "<td><input type=text name=txtBeginDate id=txtBeginDate_" + customerNum.toString() + " />";
39 targetDivHtml += "<a href=javascript:show_calendar('form1.txtBeginDate_" + customerNum.toString() + "'); style='color:#0000ff; text-decoration: none' title=Open Calender >";
40 targetDivHtml += "<img alt='' style='border:0px' height=14 src=http://www.cnblogs.com/Jscript/icon1.gif width=16 /></a> ";
41 targetDivHtml += "</td>";
42 targetDivHtml += "<td class=tdField>Manufacturer:</td>";
43 targetDivHtml += "<td><input type=text name=txtManufacturer /></td>";
44 targetDivHtml += "</tr>";
45 targetDivHtml += "<tr>";
46 targetDivHtml += "<td class=tdField> Manufacturer Location/Contact Info:</td>";
47 targetDivHtml += "<td colspan=3><input type=text name=txtInfo /></td>";
48 targetDivHtml += "</tr></table>";
49
50 var divT = document.getElementById("divEndCustomer");
51 divT.innerHTML += targetDivHtml;
52 document.getElementById("btnDelete").style.display = "";
53 return false;
54 }
55
56 function DeleteCustomer()
57 {
58 var divT = document.getElementById("divEndCustomer");
59 var tableD = document.getElementById("table_" + customerNum.toString());
60 var resultH;
61 if (customerNum != 1)
62 {
63 document.getElementById("btnDelete").style.display = "";
64 resultH = divT.removeChild(tableD);
65 }
66 else
67 {
68 document.getElementById("btnDelete").style.display = "none";
69 alert("Please ensure one end customer!");
70 }
71 if(resultH)
72 {
73 customerNum = customerNum -1 ;
74 }
75 return false;
76 }
Html部分


1 <div id="divEndCustomer" style="background-color:#99ffff;width:100%;font-family:Arial;font-size:12px;">
2 </div>
3 <input type="button" id="btnAddEndCustomer" value="More EndCustomer" class="usualButton" onclick="return AddEndCustomer();" />
4 <input type="button" id="btnDelete" value="Cancel" style="display:none" class="usualButton" onclick="return DeleteCustomer();" />
Add EndCustomer这个按钮事件对应的为AddEndCustomer(),Cancel这个按钮事件对应的为DeleteCustomer()。下面上最主要的Request部分代码:


1
2 Dim theEndCustomerInfo As New InquiryReferenceDesignEndCustomerInfo
3 Dim theEndCustomerApp As New InquiryReferenceDesignEndCustomerApp
4 Dim listOfReturnValue As New List(Of BizNetReturnValue)
5
6 Dim companyName As String = Request.Form("txtCompanyName")
7 Dim individualName As String = Request.Form("txtIndividualName")
8 Dim streetAddress As String = Request.Form("txtStreet")
9 Dim city As String = Request.Form("txtCity")
10 Dim state As String = Request.Form("txtState")
11 Dim zip As String = Request.Form("txtZip")
12 Dim phoneNumber As String = Request.Form("txtPhone")
13 Dim email As String = Request.Form("txtEmail")
14 Dim eau As String = Request.Form("txtEAU")
15 Dim beginDate As String = Request.Form("txtBeginDate")
16 Dim manufacturer As String = Request.Form("txtManufacturer")
17 Dim contactInfo As String = Request.Form("txtInfo")
18
19 Dim companyNameStr() As String = companyName.Split(","c)
20 Dim individualNameStr() As String = individualName.Split(","c)
21 Dim streetAddressStr() As String = streetAddress.Split(","c)
22 Dim cityStr() As String = city.Split(","c)
23 Dim stateStr() As String = state.Split(","c)
24 Dim zipStr() As String = zip.Split(","c)
25 Dim phoneNumberStr() As String = phoneNumber.Split(","c)
26 Dim emailStr() As String = email.Split(","c)
27 Dim eauStr() As String = eau.Split(","c)
28 Dim beginDateStr() As String = beginDate.Split(","c)
29 Dim manufacturerStr() As String = manufacturer.Split(","c)
30 Dim contactInfoStr() As String = contactInfo.Split(","c)
31
32 For i As Integer = 0 To companyNameStr.Length - 1
33 If companyNameStr(i).Trim <> "" Or streetAddressStr(i).Trim <> "" Or streetAddressStr(i).Trim <> "" Or cityStr(i).Trim <> "" Or stateStr(i).Trim <> "" Or zipStr(i).Trim <> "" Or phoneNumberStr(i).Trim <> "" Or emailStr(i).Trim <> "" Or eauStr(i).Trim <> "" Or beginDateStr(i).Trim <> "" Or manufacturerStr(i).Trim <> "" Or contactInfoStr(i).Trim <> "" Then
34 theEndCustomerInfo.ReferenceDesignInquiryID = Me.hdfInquiryID.Value
35 theEndCustomerInfo.RequestIDNumber = Me.lblRequestID.Text
36 theEndCustomerInfo.EndCustomerID = "EC_" & _MF.Gen_Key(8)
37 theEndCustomerInfo.CompanyName = companyNameStr(i)
38 theEndCustomerInfo.IndividualName = individualNameStr(i)
39 theEndCustomerInfo.StreetAddress = streetAddressStr(i)
40 theEndCustomerInfo.City = cityStr(i)
41 theEndCustomerInfo.StateOrCountry = stateStr(i)
42 theEndCustomerInfo.ZipOrPostalCode = zipStr(i)
43 theEndCustomerInfo.PhoneNumber = phoneNumberStr(i)
44 theEndCustomerInfo.Email = emailStr(i)
45 theEndCustomerInfo.EAU = eauStr(i)
46 theEndCustomerInfo.ProductionBeginDate = beginDateStr(i)
47 theEndCustomerInfo.Manufacturer = manufacturerStr(i)
48 theEndCustomerInfo.ManufacturerLocationOrContactInfo = contactInfoStr(i)
49
50 Dim theEndCustomerReturnValue As New BizNetReturnValue
51 theEndCustomerReturnValue = theEndCustomerApp.EndCustomerAdd(theEndCustomerInfo)
52 listOfReturnValue.Add(theEndCustomerReturnValue)
53 End If
54 Next
以上第51行为本人自己的DAO访问类,该为自己的即可。希望能对大家能有所帮助。^_^