Value o type 'Control' cannot be converted to 'Label' in vb.net

Eclipse MV8000 6 Reputation points
2022-08-26T18:01:20.743+00:00

I have done extensive searching for how to retrieve the information from a datalist and populate a text box and I have seen basically the same response, and I keep getting the same error.

Here is a sample of code that was previously supplied inside this MSDN forum that apparently worked for someone:

Protected Sub NegotiationsUpdatesDataList_EditCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles UpdatesDataList.EditCommand

dim lbl as Label = CType(e.Item.FindControl("lblText"), Label)  
UpdateText.Text = lbl.Text  

End Sub

No matter if I use CType, DirectCast or TryCast I get the same error:
Value o type 'Control' cannot be converted to 'Label'

I am using asp.net with vb code behind and in my code behind I am using:
Imports System.Windows.Forms

Any help with why this seems the only way to do this, and yet I get errors...

Developer technologies | VB
Developer technologies | ASP.NET | Other
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.