```
'Default.aspx
<tr bgcolor="#0000CC">
<td class="auto-style42"><strong>開單日期</strong></td>
<td class="auto-style42"><strong>產出品名</strong></td>
<td class="auto-style42"><strong>生產線別</strong></td>
.
.
.
.
<td class="auto-style42"><strong>備註</strong></td>
</tr>
<tr class="auto-style30">
<td class="auto-style37"><strong>
<asp:TextBox ID="開單日期" Type="TextBox" runat="server" CssClass="auto-style50" Width="110px" MaxLength="10" Wrap="false"> </asp:TextBox>
</strong></td>
<td class="auto-style37"><strong>
<asp:TextBox ID="產出品名" Type="TextBox" runat="server" CssClass="auto-style50" Width="110px" MaxLength="8"></asp:TextBox>
</strong></td>
<td class="auto-style37"><strong>
<select id="生產線別" runat="server" class="auto-style32" name="D3">
<option value="製前">製前</option>
<option value="製銅">製銅</option>
<option value="製鋼">製鋼</option>
<option value="加工-分條">加工-分條</option>
<option value="加工-接卷">加工-接卷</option>
</select>
</strong></td>
.
.
.
.
<asp:TextBox ID="備註1" runat="server" CssClass="auto-style61" Type="textarea" Width="200px" Height="40px" TabIndex="14" TextMode="MultiLine" title="按Enter可換行輸入"></asp:TextBox>
</strong></td>
</tr>
```
```vbnet
'Default.aspx.vb
Protected Sub BT_新增Click(sender As Object, e As EventArgs) Handles BT_新增.Click
Dim myMessage As String
Dim JavaScript As String
Dim 欄位, 資料 As String
Dim RR As Integer = CInt(Trim(SL_接卷數.Value))
Dim 生產線別 As String = ""
Dim PI卷號 As String = ""
Dim 製前批號 As String = ""
Dim 投入批號 As String = ""
Dim 製單長度 As String = ""
Dim 製單面積 As String = ""
Dim 備註 As String = ""
'迴圈檢查所有資料,DB是否有重複【工單單號】+【卷號】+【製前批號】+【投入批號】
For i = 1 To RR
生產線別 = CType(Me.Page.FindControl("生產線別" & i), TextBox).Text
卷號 = CType(Me.Page.FindControl("卷號" & i), TextBox).Text
製前批號 = CType(Me.Page.FindControl("製前批號" & i), TextBox).Text
投入批號 = CType(Me.Page.FindControl("投入批號" & i), TextBox).Text
Conn.Open()
cmd.Connection = Conn
cmd.CommandText = "SELECT * FROM PC WHERE OrderNo = '" & 工單單號.Text & "' AND Line = '" & 生產線別 & "' AND PI = '" & 卷號 & "' AND FE_LotNo = '" & 製前批號 & "' AND In_LotNo = '" & 投入批號 & "'"
Response.Write(cmd.CommandText)
dr = cmd.ExecuteReader()
SQLT.Text = cmd.CommandText
'若DB裡有此筆資料,則警告並跳出
If dr.Read() Then
myMessage = "筆】資料庫裏已有此筆資料!\n請檢查重覆的key值\n【工單單號】:" & 工單單號.Text & "\n【生產線別】:" & 生產線別 & "\n【卷號】:" & 卷號 & "\n【製前批號】:" & 製前批號 & "\n【投入批號】:" & 投入批號
JavaScript = "<script language='javascript'>window.alert('【第" & i & myMessage & "');</script>"
Me.ClientScript.RegisterStartupScript(Me.GetType, "msg", JavaScript)
dr.Close()
Conn.Close()
Exit Sub
End If
dr.Close()
Conn.Close()
Next
'迴圈寫入所有資料
For i = 1 To RR
卷號 = CType(Me.Page.FindControl("卷號" & i), TextBox).Text
製前批號 = CType(Me.Page.FindControl("製前批號" & i), TextBox).Text
投入批號 = CType(Me.Page.FindControl("投入批號" & i), TextBox).Text
製單長度 = CType(Me.Page.FindControl("製單長度" & i), TextBox).Text
製單面積 = CType(Me.Page.FindControl("製單面積" & i), TextBox).Text
備註 = CType(Me.Page.FindControl("備註" & i), TextBox).Text
'串SQL新增欄位字串
欄位 = "PC_Date,GradeNo,Line,OrderNo,FE_LotNo,In_LotNo,.....,Remark"
資料 = "'" & Me.開單日期.Text & "','" & 產出品名.Text & "','" & 生產線別 & "','" & 工單單號.Text & "',.....,'" & 備註 & "'"
'當不是【加工-分條】和【加工-接卷】時,加入【產出批號】
If 生產線別 <> "加工-分條" And 生產線別 <> "加工-接卷" Then
欄位 = 欄位 & ",Out_LotNo"
資料 = 資料 & ",'" & 產出批號.Text & "'"
End If
'新增資料寫進DB
Conn.Open()
Comd.Connection = Conn
Comd.CommandText = "INSERT INTO PC (" & 欄位 & ") VALUES(" & 資料 & ")"
Response.Write(cmd.CommandText)
dr = cmd.ExecuteReader()
dr.Close()
Conn.Close()
Next
myMessage = "新增" & RR & "筆資料完成!"
JavaScript = "<script language='javascript'>window.alert('" & myMessage & "');</script>"
Me.ClientScript.RegisterStartupScript(Me.GetType, "msg", JavaScript)
dr.Close()
Conn.Close()
'Response.Write("<script language=javascript>window.location.reload();</script>")
'Response.Redirect(Request.FilePath)
Exit Sub
End Sub
```
id竟然用中文...
我寫了一個簡單的,
.aspx
<form id="form1" runat="server">
<select id="生產線別" runat="server" class="auto-style32" name="D3">
<option value="製前">製前</option>
<option value="製銅">製銅</option>
<option value="製鋼">製鋼</option>
<option value="加工-分條">加工-分條</option>
<option value="加工-接卷">加工-接卷</option>
</select>
<button type="submit" runat="server" id="Summit">
確定
</button>
</form>
.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
int index = 生產線別.SelectedIndex;
string text = 生產線別.Items[index].Text;
}
不過如果要用WebForm可以考慮直接用WebForm提供的控制項,
可以處理比較多事件.