ASP.net Issue retrieving data from a bound GridView

Murray Brown
Murray Brown used Ask the Experts™
on
Hi

I am getting the following error "oShaft      Cannot obtain value of the local variable or argument because it is not available at this instruction pointer, possibly because it has been optimized away"
There are three rows of data in the GridView. I have included the html for the GridView below.


            Dim oGridView As GridView = Me.GridViewData
           Dim oGridViewRow As GridViewRow
            For i As Integer = 0 To oGridView.Rows.Count - 1

                oGridViewRow = GridViewData.Rows(i)

                Dim lblShaft As Label = oGridViewRow.FindControl("lblShaft")
                oShaft = lblShaft.Text

Open in new window


<asp:GridView ID="GridViewData" runat="server" AllowSorting="True" AutoGenerateColumns="False">
             <Columns>
                 <asp:TemplateField HeaderText="Shaft" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="true" SortExpression="Shaft">
                     <ItemTemplate>
                         <asp:Label ID="lblShaft" runat="server" Text='<%# Bind("Shaft")%>'></asp:Label>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="Site" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="true" SortExpression="Site">
                     <ItemTemplate>
                         <asp:Label ID="lblSite" runat="server" Text='<%# Bind("Site")%>'></asp:Label>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="Category" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="true" SortExpression="Category">
                     <ItemTemplate>
                         <asp:Label ID="lblCategory" runat="server" Text='<%# Bind("Category")%>'></asp:Label>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="Hole Number" ItemStyle-HorizontalAlign="Right" ItemStyle-Wrap="true" SortExpression="Hole Number">
                     <ItemTemplate>
                         <asp:TextBox ID="txtHoleNumber" runat="server" Text='<%# Bind("[Hole Number]")%>' Width="120"></asp:TextBox>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="Start" ItemStyle-HorizontalAlign="Right" ItemStyle-Wrap="true" SortExpression="Start">
                     <ItemTemplate>
                         <asp:TextBox ID="txtStart" runat="server" Text='<%# Bind("[Start]")%>' Width="70"></asp:TextBox>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="Stop" ItemStyle-HorizontalAlign="Right" ItemStyle-Wrap="true" SortExpression="Stop">
                     <ItemTemplate>
                         <asp:TextBox ID="txtStop" runat="server" Text='<%# Bind("[Start]")%>' Width="70"></asp:TextBox>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="Unit" ItemStyle-HorizontalAlign="Right" ItemStyle-Wrap="true" SortExpression="Unit of Measurement">
                     <ItemTemplate>
                         <asp:TextBox ID="txtUnitofMeasurement" runat="server" Text='<%# Bind("[Unit of Measurement]")%>' Width="70"></asp:TextBox>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="DescID" ItemStyle-HorizontalAlign="Right" ItemStyle-Wrap="true" SortExpression="DescriptionID">
                     <ItemTemplate>
                         <asp:TextBox ID="txtLesediDescriptionID" runat="server" Text='<%# Bind("[DescriptionID]")%>' Width="70"></asp:TextBox>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText=" Lesedi Description" ItemStyle-HorizontalAlign="Right" ItemStyle-Wrap="true" SortExpression="Description">
                     <ItemTemplate>
                         <asp:TextBox ID="txtLesediDescription" runat="server" Text='<%# Bind("[Description]")%>' Width="250"></asp:TextBox>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="Quantity" ItemStyle-HorizontalAlign="Right" ItemStyle-Wrap="true" SortExpression="Quantity">
                     <ItemTemplate>
                         <asp:TextBox ID="txtQuantity" runat="server" Text="<%#Eval(“Quantity”, ”{0:N0}”)%>" Width="80"></asp:TextBox>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="Rate" ItemStyle-HorizontalAlign="Right" ItemStyle-Wrap="true" SortExpression="Rate">
                     <ItemTemplate>
                         <asp:TextBox ID="txtRate" runat="server" Text="<%#Eval(“Rate”, ”{0:N0}”)%>" Width="80"></asp:TextBox>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="Price" ItemStyle-HorizontalAlign="Right" ItemStyle-Wrap="true" SortExpression="Price">
                     <ItemTemplate>
                         <asp:TextBox ID="txtPrice" runat="server" Text="<%#Eval(“Price”, ”{0:N0}”)%>" Width="80"></asp:TextBox>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="Hole and Site" ItemStyle-HorizontalAlign="Right" ItemStyle-Wrap="true" SortExpression="Hole and Site">
                     <ItemTemplate>
                         <asp:TextBox ID="txtHoleAndSite" runat="server" Text='<%# Bind("[Hole and Site]")%>' Width="200"></asp:TextBox>
                     </ItemTemplate>
                 </asp:TemplateField>
             </Columns>
         </asp:GridView>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial