How to see GridView data in JavaScript?

Discussion in 'ASP .Net' started by Steve Kershaw, Jul 19, 2007.

  1. 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
    Steve Kershaw, Jul 19, 2007
    #1
    1. Advertising

  2. Steve Kershaw

    David Wier Guest

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

    --
    David Wier
    MVP/ASPInsider
    http://aspnet101.com
    http://iWritePro.com



    "Steve Kershaw" <> wrote in message
    news:...
    > 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
    >
    David Wier, Jul 19, 2007
    #2
    1. Advertising

  3. On Jul 19, 8:11 am, "David Wier" <>
    wrote:
    > Could you explain, with a little more detail, what exactly you are trying to
    > accomplish?
    >
    > --
    > David Wier
    > MVP/ASPInsiderhttp://aspnet101.comhttp://iWritePro.com
    >
    > "Steve Kershaw" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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- Hide quoted text -

    >
    > - 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
    Steve Kershaw, Jul 19, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Flip
    Replies:
    3
    Views:
    972
    Tony Morris
    Feb 9, 2004
  2. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    17,959
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  3. Steve Kershaw
    Replies:
    1
    Views:
    353
    Brennan Stehling
    Sep 26, 2006
  4. admyc
    Replies:
    2
    Views:
    234
    Thomas 'PointedEars' Lahn
    Sep 4, 2007
  5. pete
    Replies:
    4
    Views:
    171
    Denis McMahon
    Jul 31, 2010
Loading...

Share This Page