将网格视图中的数据读入文本框vb

时间:2017-04-22 15:02:05

标签: asp.net vb.net gridview

我正在尝试将检索到Gridview中的数据读取到文本框中。我的想法是将gridview隐藏为使用它从我需要在文本框中显示的表中检索数据,但我不希望显示gridview。

到目前为止,我已尝试过此代码:

Protected Sub btnFindRepair_Click(sender As Object, e As EventArgs) Handles btnFindRepair.Click
    Dim row1 As GridViewRow = GridView1.SelectedRow
    txtFname.Text = row1.Cells(3).Text
    txtLname.Text = row1.Cells(4).Text
    txtContactNum.Text = row1.Cells(5).Text
    txtAltContactNum.Text = row1.Cells(6).Text
    txtAddress.Text = row1.Cells(7).Text
End Sub

然而,这给了我以下错误

  

App_Web_lfjfpvke.dll中发生了'System.NullReferenceException'类型的异常,但未在用户代码中处理

附加信息:未将对象引用设置为对象的实例

我检查了所有对象和实例,似乎无法找到null值来自哪里

这是我的gridview代码

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" DataKeyNames="Repair_ID">
    <Columns>
        <asp:BoundField DataField="Repair_ID" HeaderText="Repair_ID" SortExpression="Repair_ID" InsertVisible="False" ReadOnly="True" Visible="False" />
        <asp:BoundField DataField="Booking_Number" HeaderText="Booking_Number" SortExpression="Booking_Number" Visible="False" />
        <asp:BoundField DataField="Tracking_Number" HeaderText="Tracking_Number" SortExpression="Tracking_Number" Visible="False" />
        <asp:BoundField DataField="First_Name" HeaderText="First_Name" SortExpression="First_Name" />
        <asp:BoundField DataField="Last_Name" HeaderText="Last_Name" SortExpression="Last_Name" />
        <asp:BoundField DataField="Contact_Number" HeaderText="Contact_Number" SortExpression="Contact_Number" />
        <asp:BoundField DataField="Alternative_Contact_Number" HeaderText="Alternative_Contact_Number" SortExpression="Alternative_Contact_Number" />
        <asp:BoundField DataField="Customer_Address" HeaderText="Customer_Address" SortExpression="Customer_Address" />
    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Database %>" SelectCommand="SELECT * FROM [Customer] WHERE ([Tracking_Number] = @Tracking_Number)">
    <SelectParameters>
        <asp:ControlParameter ControlID="txtTrackingNumber" Name="Tracking_Number" PropertyName="Text" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>

0 个答案:

没有答案