Vb.net 读取gridview数据并将其输出到屏幕

Vb.net 读取gridview数据并将其输出到屏幕,vb.net,gridview,Vb.net,Gridview,我试图读取每一行的datetime并将其写入屏幕,但我一直得到System.NullReferenceException:Object reference未设置为对象的实例。网格中有数据,所以我不确定为什么在“orderDate”列中找不到任何内容 For Each r As GridViewRow in gdvOrders.Rows If r.RowType = DataControlRowType.DataRow Then

我试图读取每一行的datetime并将其写入屏幕,但我一直得到System.NullReferenceException:Object reference未设置为对象的实例。网格中有数据,所以我不确定为什么在“orderDate”列中找不到任何内容

        For Each r As GridViewRow in gdvOrders.Rows
            If r.RowType = DataControlRowType.DataRow Then
                Dim orderDate As datetime
                orderDate = r.Cells(7).FindControl("orderDate").ToString 
                Dim test as string=orderDate.ToString("yyyy-MM-dd HH:mm:ss")
                response.write(test)
            End If
        Next r



        <asp:GridView ID="gdvSentOrders" width="100%" runat="server" style="font-size:1.5em" ShowHeaderWhenEmpty="True" EmptyDataText="No orders" AllowPaging="True" AutoGenerateColumns="False" CssClass="mGrid" DataKeyNames="orderID" DataSourceID="DSSentOrders" PageSize="20" AllowSorting="True">
            <AlternatingRowStyle CssClass="alt" />
            <Columns>    
                <asp:TemplateField HeaderText="Order">
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("stallMessage") %>' />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="price" HeaderText="Price" />
                <asp:BoundField DataField="city" HeaderText="Address" />
                <asp:BoundField DataField="postcode" HeaderText="Postcode" />
                <asp:BoundField DataField="phoneNumber" HeaderText="Phone No" />
                <asp:BoundField DataField="tblNo" HeaderText="Table" />
                <asp:BoundField DataField="type" HeaderText="Type" />
                <asp:BoundField DataField="orderDate" DataFormatString="{0: H:mm:ss}" HeaderText="Order Time" SortExpression="orderDate" />
                <asp:BoundField DataField="timeFor" DataFormatString="{0: H:mm:ss}" HeaderText="Time For" SortExpression="timeFor" />
                <asp:BoundField DataField="paid" HeaderText="Paid" />

            </Columns>
        </asp:GridView>
gdvOrders.Rows中每个r作为GridViewRow的

如果r.RowType=DataControlRowType.DataRow,则
将orderDate设置为datetime
orderDate=r.Cells(7).FindControl(“orderDate”).ToString
作为字符串的Dim测试=orderDate.ToString(“yyyy-MM-dd HH:MM:ss”)
响应。写入(测试)
如果结束
下一个r

您从哪里获得此异常?我的意思是在哪一行?在这一行:orderDate=r.Cells(7).FindControl(“orderDate”).ToString