Monday, July 16, 2012

c#,asp.net - Disable html input Radio Button inside a ListView dynamically

ListView_ItemDataBound event can used to modify the controls inside the ListView in codebehind.The below code is to disable html input radio buttons inside a listview.

protected void MyListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
        ListViewDataItem dataItem = (ListViewDataItem)e.Item;
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            HtmlInputRadioButton oRadioButton = (HtmlInputRadioButton)dataItem.FindControl("MyRadioButton");
            if (oRadioButton != null && MyConditionEqualsTrue) //Based on certain condition
                  oRadioButton.Attributes["disabled"] = "disabled";
         }
}

No comments: