2014-10-03 6 views
0

formview 내에서 레이블의 텍스트를 변경하려고합니다. 이론적으로 사용자가 버튼을 클릭하면 SQL 테이블로 이동하여 데이터를 추출하고 Description이라는 레이블에 새 텍스트를 입력해야합니다. 이것은 데이터 오류이므로 "개체 참조가 개체의 인스턴스로 설정되지 않았습니다"라는 오류 메시지가 나타나면 이것이 내 문제의 일부라고 의심됩니다. 다음은 변경 formview 데이터 바인딩 된 레이블 텍스트

는 ASP 부분입니다 (죄송하지만이 ASP에 입력으로 정확히 표시되지 않습니다) :

TD 클래스 = "style29"열 병합 = "4"스타일 = "국경을 : 1 x 1 픽셀 고체 # 000000 "> 강한> 설명 :/강한>

ASP : 라벨 ID ="DescriptionLabel "RUNAT ="서버 " 텍스트 = '<% # 바인드 ("정보 ") %>'폭 ="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

'FindControl'이 제대로 작동하지 않는다고 생각합니다. 시도해보십시오.

Dim lblD As Label = DirectCast(FindName("DescriptionLabel"), Label) 

그리고 작동하는지 확인하십시오.

+0

폼뷰는 "편집"모드 였고 레이블 (초보자 용)보다 텍스트 상자를 변경하려고했습니다. 나는 이것을 해결 된 것으로 표시 할 것입니다, 고마워요. –

관련 문제