troubleshooting Question

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

Avatar of wildonthefly
wildonthefly asked on
ASP.NETVisual Basic.NETMicrosoft Development
5 Comments1 Solution4779 ViewsLast Modified:
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">
            <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"
                  <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:TextBox ID="WPAID" runat="server" Text="-1391708654"></asp:TextBox>
            <asp:Button id="Button1" usesubmitbehavior="true" Text="Print WPA" OnClientClick="FillWPA()" runat="server" />
<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\", , 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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros