现在这个WAS工作,我不知道是什么 我已经改变,但任何人都可以看到为什么呼叫无效 我没有从浏览器中定义getSetContactID
这是webform的标记,包括脚本
<asp:TemplateField HeaderText="Quick Donate">
<ItemTemplate>
<asp:Button ID="btnQuickDonate" CssClass="btn-sm btn-primary" runat="server"
CommandName="Insert" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
OnClientClick='<%# "getSetContactID(\"" + Container.DataItemIndex + "\")" %>'
OnClick="btnQuickDonate_Click" Text="Quick 
Donate" />
<script type="text/javascript">
//functions returns the dataitemindex (row Number) from the btnQuickDonate (which is the contactID)
function getSetContactID(rowIndex, obj) {
var CellValue, cell, dataItemIndex;
var table = document.getElementById('<%=GridView1.ClientID %>');
cell = table.rows[parseInt(rowIndex) + 1].cells[1];
//cell = document.getElementById('<%=GridView1.ClientID %>').rows[parseInt(t) + 1].cells[1];
dataItemIndex = cell.innerHTML; //this will get items inside cell (Not needed because the ContactID is hidden so using the row index in row behind with dataitemindex)
//alert(dataItemIndex + "row index" + rowIndex);
$.ajax({
type: "POST",
url: "WebService1.asmx/setContactIDGV1",
data: '{DataItemIndex: "' + rowIndex + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: "done", //after contactID taken click btnQuickDonate to set donation amount
failure: function (response) {
alert(response.d);
}
})
}
</script>
</ItemTemplate>
答案 0 :(得分:1)
将您的JS移出ItemTemplate。值得一试。
答案 1 :(得分:0)
你在函数调用
中缺少第二个参数OnClientClick='<%# "getSetContactID(\"" + Container.DataItemIndex + "\")" %>'
function getSetContactID(rowIndex, obj) {