Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Read cell values from datagrid/gridview using client-side vbscript in web app

Posted on 2007-07-20
5
Medium Priority
?
4,540 Views
Last Modified: 2008-01-09
I have created aweb application in ASP.NET 2.0 with VB.NET (VS2005) and SQL Server 2005. I have Word 2003 templates that must be filled through automation on the client-side (VBScript) - each user's location has indvidualized templates. I was hoping to be able to fill the Word doc from either a datagrid or gridview which is made up of a single row. I have a button on the page with the datagrid/gridview that triggers the VBScript, opening the bookmarked Word template. My probem is how do I read each cell from the datagrid/gridview.

The relevant code for a DataGrid is:
<form id="form1" runat="server">
        <div>
            <asp:datagrid id="DataGrid1" runat="server" GridLines="Vertical" CellPadding="3" BackColor="White"
                BorderColor="#999999" BorderWidth="1px" BorderStyle="None" Width="100%" Height="100%" Font-Size="X-Small"
                Font-Names="Verdana">
                  <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
                  <AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
                  <ItemStyle BorderWidth="2px" ForeColor="Black" BorderStyle="Solid" BorderColor="Black" BackColor="#EEEEEE"></ItemStyle>
                  <HeaderStyle Font-Bold="True" HorizontalAlign="Center" BorderWidth="2px" ForeColor="White" BorderStyle="Solid"
                  BorderColor="Black" BackColor="#000084"></HeaderStyle>
                  <FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle>
                  <PagerStyle HorizontalAlign="Center" ForeColor="Black" BackColor="#999999" Mode="NumericPages"></PagerStyle>
            </asp:datagrid>
            <asp:TextBox ID="WPAID" runat="server" Text="-1391708654"></asp:TextBox>
            <asp:Button id="Button1" usesubmitbehavior="true" Text="Print WPA" OnClientClick="FillWPA()" runat="server" />
        </div>
    </form>
<script type="text/vbscript">

        function FillWPA()
            Dim oWord, oDoc, oConn, sCommand, sReader, oGridItem
           
           
            Set oWord = CreateObject("Word.Application")
            Set oDoc = oWord.Documents.Open("C:\NM_Works_All\HSD\Templates\DWP_005.dot", , False)
            oWord.Visible = true

            oDoc.FormFields("Date").result = document.form1("DataGrid1").Item.Rows(0).Cells(2).Value
            oDoc.FormFields("Geo").result = document.form1("DataGrid1").Item.Rows(0).Cells(3).Value
            oDoc.FormFields("Adm").result = document.form1("DataGrid1").Item.Rows(0).Cells(4).Value
            .
            .
            .
            oDoc.FormFields("Edu").result = document.form1("DataGrid1").Item.Rows(0).Cells(100).Value
            oDoc.SaveAs "C:\NM_Works\Documents\WPA_Test.doc"

I get an error: Microsoft VBScript runtime error: Object required: 'document.form1(...)'

          end function
           
    </script>
0
Comment
Question by:wildonthefly
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:aki4u
ID: 19538100
try using document.forms(0) instead of document.form1
0
 

Author Comment

by:wildonthefly
ID: 19539325
New error: Microsoft VBScript runtime error: Object doesn't support this property or method: 'document.forms(...).Item.Rows'

In your solution, where do identify DataGrid1?
0
 
LVL 58

Accepted Solution

by:
amit_g earned 2000 total points
ID: 19539960
Dim oDataGrid

oDataGrid = document.getElementById("<%= DataGrid1.ClientID %>")

'Now you have instance of Table that DataGrid produces on the client side in variable oDataGrid
'You could use

FirstCellInFirstRow = oDataGrid.rows(0).cells(0).innerHTML

and so on. Keep in mind that depending upon the ItemTemplate you may have to go even deeper in cell to get exact value. Although I see that you probably are not using any.
0
 

Author Comment

by:wildonthefly
ID: 19540067
Thanks for speedy response.
Only one change; it needed Set:
Set oDataGrid = document.getElementById("<%= DataGrid1.ClientID %>")
0
 
LVL 58

Expert Comment

by:amit_g
ID: 19540095
Oh yes. I am used to Javascript on the client side :)
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question