Wednesday, May 18, 2011

RadioButtonList add title for items

Radiobuttonlist displays same title as of Item’s text. There was situation to display more informative title for Radiobuttonlist Items. Here is simple trick I found out.

 <asp:RadioButtonList ID=”rdoBtnListOptions” runat=”server” RepeatDirection=”Horizontal”>
<asp:ListItem Value=”1?>One</asp:ListItem>
<asp:ListItem Value=”2?>Two</asp:ListItem>
</asp:RadioButtonList>


 In code behind file you can add

foreach (ListItem oItem in rdoBtnListOptions.Items)
{
if (oItem.Value == “1?)
oItem.Attributes.Add(“OnMouseOver”, “this.title=’This is option one.’”);
else
oItem.Attributes.Add(“OnMouseOver”, “this.title= This is option two.”);