Last post Nov 18, 2019 12:05 PM by uid250511
Nov 18, 2019 11:39 AM|uid250511|LINK
I have two controls, a radiobuttonList and CheckboxList. I would like to retrieve the items selected within these controls.
private void ItemsInList(object c)
if (c == typeof(RadioButtonList))
else if (c == typeof(CheckBoxList))
foreach (ListItem li in c.Items)
What i'm trying to do is pass in a control (c) and then determine if its a RBL or CBL (if i need to that is) and then iterate through the list and take some action.
At present i have the above code but receive the error
'object' does not contain a definition for 'Items' and no extension method 'Items' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?
Im not entirely sure if this is possible or if im doing something wrong?
Nov 18, 2019 11:50 AM|PatriceSc|LINK
According to the doc both RadioButtonList and CheckBoxList are inheriting from the ListControl class which provides the Items property so try :
private void ItemsInList(ListControl c)
Edit: in short you should work against the more general type that provides what your code actually use
Nov 18, 2019 12:05 PM|uid250511|LINK
Thanks, been reading on Generics recently and over thought this too much.