简体   繁体   English

Javascript函数调用在gridview中不起作用

[英]Javascript function call not working within gridview

Now this WAS working, I dont know what I've changed but can anyone see why the call is not working im getting getSetContactID is not defined from the browser 现在,这个工作正常了,我不知道我已经更改了什么,但是谁能看到呼叫为什么无法工作,因为没有从浏览器中定义getSetContactID

Here is the markup from the webform including the script 这是包含脚本的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>

Move your JS out of ItemTemplate. 将JS移出ItemTemplate。 Worth a try. 值得一试。

You are missing second Argument in function calling 您在函数调用中缺少第二个参数

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



function getSetContactID(rowIndex, obj) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM