Javascript 函数调用在网格视图中不起作用

本文关键字:不起作用 视图 网格 函数调用 Javascript | 更新日期: 2023-09-27 18:35:16

现在这个正在工作,我不知道是什么我已经更改了,但任何人都可以看到为什么电话不起作用im get getSetContactID 不是从浏览器定义的

这是来自 Web 表单的标记,包括脚本

 <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 &#010;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>

Javascript 函数调用在网格视图中不起作用

将 JS 移出 ItemTemplate。值得一试。

函数调用中缺少第二个参数

OnClientClick='<%# "getSetContactID('"" + Container.DataItemIndex + "'")" %>'

function getSetContactID(rowIndex, obj) {