AShah
AShah

Reputation: 942

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

Here is the markup from the webform including the script

 <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>

Upvotes: 0

Views: 410

Answers (2)

husnain_sys
husnain_sys

Reputation: 571

Move your JS out of ItemTemplate. Worth a try.

Upvotes: 1

Dgan
Dgan

Reputation: 10275

You are missing second Argument in function calling

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



function getSetContactID(rowIndex, obj) {

Upvotes: 0

Related Questions