實在查很久,自己記錄下來
JS端
<script type="text/javascript">
var ClickNum = 0;//記錄同一checkbox連續點擊次數
var PreCheckboxID = "";//記錄點擊checkbox的ID
//listId控制checkbox的範圍
//SelectRadio是點擊checkbox自己
function SelectedSingle(listId, SelectRadio) {
///判斷是否點同一個checkbox
if (PreCheckboxID == SelectRadio.id) {
ClickNumClickNum = ClickNum + 1;
}
else {
PreCheckboxID = SelectRadio.id;
ClickNum = 0;
}
//找到範圍
var GridViewtableSearchList = document.getElementById(listId);
//找到控制範圍下所有input
var objs = GridViewtableSearchList.getElementsByTagName("input");
var gv = document.getElementById("ctl00_ContentPlaceHolder1_fgvD1");
//勾選的將fgvD1值傳給主表單IFFGAA40F
//找到控制範圍下所有checkbox都改成为false
for (var i = 0; i < objs.length; i++) {
if (objs[i].type.toLowerCase() == "checkbox")
{
objs[i].checked = false;
}
}
var SelectRadioID = SelectRadio.id;
if (ClickNum % 2 != 1) {
document.getElementById(SelectRadioID).checked = true;
}
else {
document.getElementById(SelectRadioID).checked = false;
}
for (var i = 0; i < objs.length; i++) {
if (objs[i].type.toLowerCase() == "checkbox" && objs[i].checked == true)
{
document.getElementById("ctl00_ContentPlaceHolder1_ftbVENDORNO").value = gv.rows[i].cells[1].innerHTML;
document.getElementById("ctl00_ContentPlaceHolder1_ftbVENDORNM").value = gv.rows[i].cells[4].innerHTML;
document.getElementById("ctl00_ContentPlaceHolder1_ftbVENDORAMT").value = gv.rows[i].cells[5].innerHTML;
document.getElementById("ctl00_ContentPlaceHolder1_ftbVENDORPAYMODE").value = gv.rows[i].cells[7].innerHTML;
document.getElementById("ctl00_ContentPlaceHolder1_ftbVENDORPAYDATE").value = gv.rows[i].cells[8].innerHTML;
document.getElementById("ctl00_ContentPlaceHolder1_ftbVENDORPAYDATE").value = gv.rows[i].cells[9].innerHTML;
}
}
}
ASP端
GV
<ItemTemplate>
<asp:CheckBox ID="cbVENDORCHECK" runat="server" onclick="SelectedSingle('t1_ctl00_ContentPlaceHolder1_fgvD1',this)" Width="95%" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="VENDORCHECK" HeaderText="建議廠商" Visible="false"></asp:BoundField>