简体   繁体   中英

How to get values from a GridView's templatefield textboxes in JavaScript?

Bear with me as I've googled this for days now and I have not been able to find one solution that works for me. Also bear with me as I'm new to posting here but searched for many a solution! :)

I am attempting to get some client side "agreement" when someone enters an NDA (nondisclosure agreement). Basically what I need to do is 1) run a client side script to A) check if the value in the textbox has changed B) if the value has changed ask the user if they agree that the NDA is the right one and signed by our legal team. Then C) save the data (in gridview) if agreed or clear out the data and not save if they do not agree.

As the name of the question suggests, the textbox is within a templatefield/editItemTemplate of a gridview.

All of this (if agreed) then goes into a database. So basically I need a client side script to run and take input then write to a SQL database (that part I don't need help with).

Thanks,

Best piece of code I could find was this:

<script type="text/javascript">
  function Read() {
    var oDataGrid = document.getElementById("<%= GridView1.ClientID %>")
    var tableRows = oDataGrid.rows;
    var rawDataRows = new Array();
    //somewhere to put the actual data
    for (var i = 0; i < tableRows.length; i++) {
      var thisRow = tableRows[i];
      for (var j = 0; j < thisRow.cells.length; j++) {
        alert(oDataGrid.rows(i).cells(j).innerHTML);
      }
    }
  }
</script>

basically it will iterate through all rows and all cells in rows to find exactly what you need to grab values. I hope this helps others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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