General object type

T

tshad

I want to use the same code for my DataGrid item as I do for my DataList
Item. The only difference is the data type. Is there a generic data type I
can use?

I have a datagrid inside of my data list and want to be able to select
either the dataListItem or the dataGridItem and do exactly the same thing.

For example, instead of:

Dim oDGI as DataGridItem = s.parent.parent
Dim oGrid as DataGrid = oDGI.parent.parent
Dim Answer as Label = CType(oDGI.FindControl("lblAnswer"),Label)
for each oDGI2 as DataGridItem in oGrid.Items

and

Dim oDLI as DataListItem = s.parent.parent
Dim oList as DataGrid = oDLI.parent.parent
Dim Answer as Label = CType(oDLI.FindControl("lblAnswer"),Label)
for each oDLI2 as DataListItem in oList.Items

(which same except for the object names)

Is there a way to do something like:
******************************************************
Dim oDI as DataItem ' generic DataItem
Dim oDI2 as DataItem ' generic DataItem
Dim oGridorList as ?
Dim oDLI as DataListItem
Dim oDGI as DataGridItem

if (s.id = "btnGrid") then
Dim oDGI as DataGridItem = s.parent.parent
oDI = oDGI
Dim oGrid as DataGrid = oDGI.parent.parent
oGridorList = oGrid
end if


if (s.id = "btnList") then
oDLI = s.parent.parent
oDI = oDLI
Dim oList as DataList = oDLI.parent.parent
oGridorList = oList
end if

Dim Answer as Label = CType(oDI.FindControl("lblAnswer"),Label)
for each oDI2 as DataItem in oGridorList.Items
********************************************************************

Not sure if this can be done, but it would help me to not duplicate my code.

Thanks,

Tom
 
K

Kevin Spencer

Is there a generic data type I can use?

System.Object?

System.Web.UI.Control?

System.Web.UI.Control.WebControl?

How about System.Web.UI.BaseDataList?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
T

tshad

Kevin Spencer said:
System.Object?

System.Web.UI.Control?

System.Web.UI.Control.WebControl?

How about System.Web.UI.BaseDataList?

I know about those.

But how about below where I am trying to use one variable for both a
DataListItem and DataGridItem pointer? As well as a pointer to DataGrid and
a DataList. I would mainly need this to use the FindControl method as well
as in my "for each oDI2 as DataItem in oGridorList.Items".

Tom
 
T

tshad

Kevin Spencer said:
Well, Tom, seeing as how I would have to look all that stuff up (no, I've
never tried to do what you want to do), how about I just send you to the
place I would look?

I read it but not sure if I will be able to use it or not - will try it and
see.

I didn't realize that both came from BaseDataList ( I assumed the datagrid
from come from something like BaseDataGrid).

Thanks,

Tom
 
K

Kevin Spencer

I didn't realize that both came from BaseDataList ( I assumed the
datagrid from come from something like BaseDataGrid).

That's why I included it in my list! :)

The list is a lit of all the classes that both classes inherit.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top