Findcontrol not working in VB

T

tshad

I am using sample code from C# and am trying to convert it to VB.Net in my
aspx page.

This works in C#:

DataGrid oGrid = (DataGrid)oItem.FindControl("DataGrid1");

I have tried all kinds of combinations trying to get it to work:

***********************************************************************
Dim oGrid as DataGrid
oGrid =
CType(DataGrid,DataList1.Items[DataList1.SelectedIndex].FindControl("DataGrid1"))

Gives me this error:

'DataGrid' is a type and cannot be used as an expression.
**************************************************************************************************

*****************************************************************************************************
Dim oGrid as DataGrid
oGrid = DataList1.Items[DataList1.SelectedIndex].FindControl("DataGrid1"))

Gives me this error:

Value of type 'System.Web.UI.WebControls.DataListItemCollection' cannot be
converted to 'System.Web.UI.WebControls.DataGrid'.
****************************************************************************************************

***********************************************************************************************************
Dim oGrid as DataGrid =
DataList1.Items[DataList1.SelectedIndex].FindControl("DataGrid1"))

Gives me:

Identifier expected.
**************************************************************************************************************

***************************************************************************************************************
Dim oGrid as new DataGrid =
DataList1.Items[DataList1.SelectedIndex].FindControl("DataGrid1"))

Gives me:

End of statement expected.
**************************************************************************************************************

How do I make this work?

Thanks,

Tom.
 
T

tshad

Never mind.

The correct line should be:

Dim oGrid as DataGrid =
CType(DataList1.Items(DataList1.SelectedIndex).FindControl("DataGrid1"),DataGrid)

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top