如何更改后面的vb代码中的formview数据绑定标签中的文本

时间:2014-10-03 18:50:07

标签: asp.net vb.net

我(新手)有一个程序,希望用户可以通过点击按钮更改标签中的文字。单击后,sql表将提供要在标签中输入的备用文本。我能做的最好的是提出“对象引用没有设置为对象的实例”错误。我怀疑这与数据绑定的标签有关。有人有什么建议吗?我感谢任何和所有的帮助。谢谢!

asp部分如下:

td class="style29" colspan="4" style="border: 1px solid #000000"><strong>Description:</strong>
asp:Label ID="DescriptionLabel" runat="server" 
                        Text='%# Bind("Description") %>' Width="1000px" />

后面的vb代码如下:

Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
    Dim conCString1 As String = ConfigurationManager.ConnectionStrings("conCString1").ConnectionString
    Dim sqlConnection1 As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("conCString1").ConnectionString)
    Dim cmd1 As New SqlCommand
    cmd1.CommandType = CommandType.Text
    cmd1.Connection = sqlConnection1

    Dim querystring1 As String = "SELECT [Rule] FROM [BuildRules] WHERE ([Table] = N'Capacitors') AND (Field = N'Description')"
    sqlConnection1.Open()
    Dim command2 As New SqlCommand(querystring1, sqlConnection1)
    Dim reader2 As SqlDataReader = command2.ExecuteReader()
    Dim lblD As Label = FormView1.FindControl("DescriptionLabel")

    While reader2.Read()
        'below is test line only
        lblD.Text = reader2(0) 'Example: 'CAP', Value, Dielectric Type, Package Size, Rated Voltage, Tolerance, Temperature Coefficient


    End While
    sqlConnection1.Close()

End Sub

0 个答案:

没有答案