Here is html

<asp:datagrid id="mrpDataGrid" style="Z-INDEX: 289; LEFT: 576px; POSITION: absolute; TOP: 512px" runat="server" Width="160px" Height="90px" autogeneratecolumns="False">
<AlternatingItemStyle BackColor="LightGray"></AlternatingItemStyle>
 <Columns>
  <asp:BoundColumn DataField="SCHEDULE_DT" HeaderText="Scheduled Date" DataFormatString="{0:d}"></asp:BoundColumn>
  <asp:BoundColumn DataField="SCHEDULE_QTs" HeaderText="Summed Quantity"></asp:BoundColumn>
 </Columns>
</asp:datagrid>

I need to get values of both bound columns to use in calculations.
TIA
javascript newbie

Dani AI

Generated

is right that client-side JavaScript only sees what the browser receives. ’s table loop proves the approach works when the control renders to an HTML table — the same idea applies to a DataGrid, but you must find the rendered table element (the server control’s client-side id can be changed by ASP.NET naming containers).

A reliable pattern that avoids depending on the exact ClientID is to locate the rendered table by an "id ends with" selector, select the body rows (skip header/thead), read each row’s cells, normalize the text, and convert to numbers/dates before doing calculations. Example:

// find the rendered DataGrid (works when ASP.NET prefixes ClientID)
var grid = document.querySelector('[id$="mrpDataGrid"]');
if (!grid) throw 'DataGrid not found on the page';

var rows = grid.querySelectorAll('tbody tr');
for (var i = 0; i < rows.length; i++) {
  var cells = rows[i].children;
  if (cells.length < 2) continue;

  var dateText = (cells[0].textContent || cells[0].innerText || '').trim();
  var qtyText  = (cells[1].textContent || cells[1].innerText || '').trim();

  var qty = parseFloat(qtyText.replace(/[^0-9\.\-]/g, '')) || 0;
  var dt  = new Date(dateText); // try built-in; fallback to manual parse if needed

  // now do your calculations with dt and qty
}

Troubleshooting tips: inspect the page source to confirm the real client id or set ClientIDMode="Static" / add a CSS class to the table. If the date format is locale-specific, prefer storing an ISO date (or a hidden data-* attribute) so parsing is reliable. If your grid is paged or built server-side only, pull raw values as JSON from the server instead of scraping the rendered page.

Recommended Answers

All 3 Replies

If the data are on the server computer, javascript can't see them, because javascript runs on the client computer.

the script i show puts out a aleart showing that there is 82 rows in the datagrid. i just have not been able to figure out how to get to the columns to retieve the data. i've tried navroot.rows(i). col[0], cells[0], several things and no luck.

<asp:table id="dmdTbl" style="Z-INDEX: 617; LEFT: 280px; POSITION: absolute; TOP: 552px" runat="server" Width="184px" Height="60px" >
 <asp:TableRow ID="drows" >
    <asp:TableCell ID="DmdDate" Enabled=False ></asp:TableCell>
    <asp:TableCell ID="Dqty" Enabled=False ></asp:TableCell>
 </asp:TableRow>
</asp:table>

code is this:
            var ord = 0;     // set up int
            var dd = new Date();   //set up date field
            //ord = document.getElementById('dmdTbl').rows.length;     // fid # of rows
            //alert("value "+ord);     //display number of rows
            var rowposi = document.getElementById('dmdTbl').rows;    // set position of row
            for (var i=0;i<document.getElementById('dmdTbl').rows.length;i++) {  
                 dd = rowposi[i].childNodes[0].innerText;
                 ord = rowposi[i].childNodes[1].innerText;
                 // ..... do something with dd and ord
                 //alert("value "+dd+"ord "+ord+"cnt "+i);   // show values
             }     // end for loop

I hope this help someone else.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.