How to see GridView data in JavaScript?

S

Steve Kershaw

Hi
I have an ASP.NET web page I'm working on and I need to see the
GridView Cell data in a javascript function. <%= %> doesn't work. Am I
missing something here?

Thanks
Steve
 
D

David Wier

Could you explain, with a little more detail, what exactly you are trying to
accomplish?
 
S

Steve Kershaw

Could you explain, with a little more detail, what exactly you are trying to
accomplish?

--
David Wier
MVP/ASPInsiderhttp://aspnet101.comhttp://iWritePro.com







- Show quoted text -

Actually I figured it out. What I was trying to accomplish is sucking
the data from a GridView and putting it into an Excel spreadsheet. The
JavaScript code is quite simple:

// set up the Excel spreadsheet
var exApp = new ActiveXObject("Excel.Application");
exApp.visible = true;
var workbook = exApp.Workbooks.Add();

var rowcount = document.getElementById("<
%=GridView1.ClientID").rows.length;
var colcount = document.getElementById("<%=GridView1.ClientID
%>").rows[0].cells.length;

// describe the header row
workbook.ActiveSheet.Cells(1, 1) = "STR_NBR";
workbook.ActiveSheet.Cells(1, 2) = "FIT";
workbook.ActiveSheet.Cells(1, 3) = "FITGL";
workbook.ActiveSheet.Cells(1, 4) = "FUI";
workbook.ActiveSheet.Cells(1, 5) = "FUIGL";
workbook.ActiveSheet.Cells(1, 6) = "SIT";
workbook.ActiveSheet.Cells(1, 7) = "SITGL";
workbook.ActiveSheet.Cells(1, 8) = "SUI";
workbook.ActiveSheet.Cells(1, 9) = "SUIGL";
workbook.ActiveSheet.Cells(1, 10) = "ETF";
workbook.ActiveSheet.Cells(1, 11) = "ETFGL";
workbook.ActiveSheet.Cells(1, 12) = "SDI";
workbook.ActiveSheet.Cells(1, 13) = "SDIGL";

// fill in the rest of the cells.
for(var row = 1; row < rowcount; row++)
{
for(var col = 1; col < colcount + 1; col++)
{
workbook.ActiveSheet.Cells(row + 1, col) =
document.getElementById("<%=GridView1.ClientID
%>").rows[row].cells[col - 1].innerHTML;
}
}

Note that I don't know how to get the header row. All I recieve is the
HTML to descibe the header element.

Thanks
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top