I want to be able to determine if my DataListItem type is of type RadioButton in C# code behind.
Is this possible?
Alternatively if it is not type DropDownList that would also work.
Isn't there a way to some kind of check such as
if(item.ItemType.Equals(HtmlInputRadioButton)){
//
}
item.ItemType is an enum. Type will never be HtmlInputRadioButton
public enum ListItemType
{
Header,
Footer,
Item,
AlternatingItem,
SelectedItem,
EditItem,
Separator,
Pager,
}
Instead, the code should be like this -
void Item_XXXX(Object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
// Make sure MyRadioButtonId is an ID of HtmlInputRadioButton
var htmlInputRadioButton = e.Item.FindControl("MyRadioButtonId")
as HtmlInputRadioButton;
}
}