Label giving problem
-
Dim SubHeader As String Dim dt As New DataTable dt = dst.Tables("MySubSections") Dim dr As DataRow Dim dc As DataColumn For Each dr In dt.Rows 'SubHeader = dst.Tables(0).Columns(0).ToString SubHeader = dr("MainPage").ToString Next Label4.Text = SubHeader THIS IS REPEATER I WANT LABEL TO BE DISPLAYED IN REPEATER Label IT IS GIVING NULL REFERENCE EXCEPTION. IF I DEBUG, I CAN SEE THE VALUE TO BE DISPLAYED IN VARIABLE “SubHeader” however, it gives me null reference exception Thanks Needy
-
Dim SubHeader As String Dim dt As New DataTable dt = dst.Tables("MySubSections") Dim dr As DataRow Dim dc As DataColumn For Each dr In dt.Rows 'SubHeader = dst.Tables(0).Columns(0).ToString SubHeader = dr("MainPage").ToString Next Label4.Text = SubHeader THIS IS REPEATER I WANT LABEL TO BE DISPLAYED IN REPEATER Label IT IS GIVING NULL REFERENCE EXCEPTION. IF I DEBUG, I CAN SEE THE VALUE TO BE DISPLAYED IN VARIABLE “SubHeader” however, it gives me null reference exception Thanks Needy
Hi there, I guess the Label4 object is null, and you cannot access the Text property. How do you get reference to the label declared in the header of the repeater control? Because the Label is placed inside the repeater control, so you cannot simply add the declaration for the control in code-behind as you would with other controls placed in the web page. In this case, you can create an event handler for the ItemDataBound event of the repeater, then look for the label placed in the header item using the FindControl method. Once you have reference to to the label, you then can assign a value to the Text property.