我試圖通過表循環來查看是否選中了複選框。在按鈕上單擊SendCheckEmail被調用。我得到一個錯誤EmailForm沒有聲明,我也不確定如何循環遍歷表來處理每個選中的複選框。如何通過表循環查看複選框是否被選中
Sub Page_Load
If Request.QueryString("show") <> "" then
dim Sr as StreamReader = New StreamReader("d:\netdrvs\prs\emaillist\" & Request.QueryString("show"),FileMode.Open)
output="<table id=EmailForm border=1 padding=4 >" & VBCR
output+="<tr><td>Customer Code</td><td>Email</td><td>Invoice Number</td><td>Regarding</td><td> <input type=checkbox name=chkHeader id=chkHeader></td></tr>"
While Not SR.EndOfStream
dim Temp(3) as String
Temp = Split(SR.ReadLine(),vbTab)
dim temp2(3) as String
Temp2 = Split(Temp(0),"_")
output += "<tr>" & VBCR
output += "<td>" & Temp2(1) & "</td>" & VBCR
output += "<td>" & Temp(1) & "</td>" & VBCR
output += "<td>" & Temp2(0) & "</td>" & VBCR
output += "<td>" & Temp(2) & "</td>" & VBCR
output += "<td> <input type=checkbox name=chkRow id=chkRow> </td>" & VBCR
output += "</tr>"& VBCR
End While
output+="</table>" & VBCR
SR.Close()
ProcessChk.Visible = True
end if
End Sub
Sub SendCheckEmail (sender As Object, e As System.EventArgs)
Dim item
For each item in EmailForm
'loop through each row
NEXT
End Sub
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Lathams Invoice Email Sending</title>
<script type="text/javascript" src="ajax.googleapis.js"></script>
<script type="text/javascript">
$("[id*=chkHeader]").live("click", function() {
var chkHeader = $(this);
var grid = $(this).closest("table");
$("input[type=checkbox]", grid).each(function() {
if (chkHeader.is(":checked")) {
$(this).attr("checked", "checked");
$("td", $(this).closest("tr")).addClass("selected");
} else {
$(this).removeAttr("checked");
$("td", $(this).closest("tr")).removeClass("selected");
}
});
});
$("[id*=chkRow]").live("click", function() {
var grid = $(this).closest("table");
var chkHeader = $("[id*=chkHeader]", grid);
if (!$(this).is(":checked")) {
$("td", $(this).closest("tr")).removeClass("selected");
chkHeader.removeAttr("checked");
} else {
$("td", $(this).closest("tr")).addClass("selected");
if ($("[id*=chkRow]", grid).length == $("[id*=chkRow]:checked", grid).length) {
chkHeader.attr("checked", "checked");
}
}
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:label id="test" runat="server" />
<%=output%>
<p> </p>
<asp:Button id="ProcessFile" visible="false" runat="server" Text="Process Emails" onClick="SendMails" />
<asp:Button id="ProcessChk" visible="false" runat="server" Text="Process Checked Emails" OnClick="SendCheckEmail" />
</form>
</body>
</html>
顯示你的.aspx頁面中 – 2014-09-30 19:15:34
好吧!我已經重新編輯我的問題 – Sash 2014-09-30 19:21:14
EmailForm是哪個控件?你是否使用任何'Repeater',GridView' – 2014-09-30 19:25:54