<%@ Page Title="" Language="VB" MasterPageFile="~/Downloadform/downloadform/masterform.master" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
Sub ddlNum_Changed(sender As Object, e As System.EventArgs)
Dim i As Integer
Dim fileUpload As FileUpload
Dim nameform As TextBox
Dim lblBr As Label
Dim lblText As Label
Dim lblTextup As Label
For i = 1 To Me.ddlNum.SelectedItem.Value
fileUpload = New FileUpload
nameform = New TextBox
lblText = New Label
lblTextup = New Label
With lblText
.Text = "ชื่อไฟล์ :"
'.Font.Size = "30"
End With
With nameform
.ID = "textnameform" & i
End With
With lblTextup
.Text = "อัพโหลดไฟล์ :"
'.Font.Size = "30"
End With
With fileUpload
.ID = "fiUpload" & i
End With
lblBr = New Label
lblBr.Text = "<br>"
Me.pnlCtrl.Controls.Add(lblText)
Me.pnlCtrl.Controls.Add(nameform)
Me.pnlCtrl.Controls.Add(lblTextup)
Me.pnlCtrl.Controls.Add(fileUpload)
Me.pnlCtrl.Controls.Add(lblBr)
Next
IF Me.ddlNum.SelectedItem.Value > 0 Then
Me.btnUpload.Visible = True
Else
Me.btnUpload.Visible = False
End IF
Me.form1.Enctype = "multipart/form-data"
End Sub
Sub btnUpload_OnClick(sender As Object, e As EventArgs)
Dim i As Integer
Dim myUpoad As HttpFileCollection = Request.Files
Dim myFiles As HttpPostedFile
Dim strSQL As String
Dim insertform As String
Dim maxidtypeform As String
Dim ComEdit As OleDbCommand
Dim Conn As OleDbConnection
Dim MaxID As Integer
For i = 0 To Me.ddlNum.SelectedItem.Value - 1
myFiles = myUpoad(i)
If myUpoad.Keys(i).ToString = ("fiUpload" & i + 1).ToString Then '*** Check Control ***'
If (myFiles.FileName) <> "" Then
Dim strFileName = System.IO.Path.GetFileName(myFiles.FileName)
myFiles.SaveAs(Server.MapPath("file/FireDrill52/" & strFileName))
' filPicture.PostedFile.SaveAs(Server.MapPath("file/FireDrill52/" & strFileName))
strSQL = "INSERT INTO form (Nametypeform) " & _
" VALUES ('" & texttypeform.Text & "') "
maxidtypeform = "SELECT MAX(Idtypeform) FROM typeform"
ComEdit = New OleDbCommand(maxidtypeform, Conn)
MaxID = ComEdit.ExecuteScalar()
insertform = "INSERT INTO typeform (Idtypeform,Nameform) " & _
" VALUES (" & MaxID & "),'" &[color=blue] nameform.textnameform & "' "
Me.lblText.Text = Me.lblText.Text & strFileName & " Uploaded.<br>"
End If
End If
Next
Me.lblText.Visible = True
Me.btnUpload.Visible = False
Me.ddlNum.Visible = False
End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<form id="form1" runat="server">
ชื่อแบบฟอร์ม : <asp:TextBox id="texttypeform" runat ="server" size="50"></asp:TextBox><br />
เลือกจำนวนไฟล์ที่ต้องการอัพโหลด :
<asp:DropDownList id="ddlNum" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlNum_Changed">
<asp:ListItem Text="0" Value="0"></asp:ListItem>
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
<asp:ListItem Text="4" Value="4"></asp:ListItem>
<asp:ListItem Text="5" Value="5"></asp:ListItem>
<asp:ListItem Text="6" Value="6"></asp:ListItem>
<asp:ListItem Text="7" Value="7"></asp:ListItem>
<asp:ListItem Text="8" Value="8"></asp:ListItem>
<asp:ListItem Text="9" Value="9"></asp:ListItem>
<asp:ListItem Text="10" Value="10"></asp:ListItem>
</asp:DropDownList>
<asp:Panel id="pnlCtrl" runat="server"></asp:Panel>
<input id="btnUpload" Visible="false" type="button" OnServerClick="btnUpload_OnClick" value="เพิ่มไฟล์อัพโหลด" runat="server" />
<asp:Label id="lblText" runat="server"></asp:Label>
</form>
</asp:Content>