views:

2269

answers:

2

I'm trying to add some onmouseover and onmouseout attributes to any of the <input>, <td>, or <label> elements for each ListItem of a RadioButtonList. How do I do this? Here's what I've tried. This does not work...

ASPX File...

<asp:RadioButtonList ID="RadioButtonListPaymentFrequency"
    runat="server"
    RepeatDirection="Vertical"
    RepeatLayout="Table"
    RepeatColumns="1" />

VB Code Behind...

Dim ListItemOneTimeOnly As New ListItem("One-Time Only", "1")
ListItemOneTimeOnly.Attributes.Add("onmouseover", "ddrivetip('Example: $300 total amount paid one-time means 1 payment of $300.')")
ListItemOneTimeOnly.Attributes.Add("onmouseout", "hideddrivetip()")
RadioButtonListPaymentFrequency.Items.Add(ListItemOneTimeOnly)

Dim ListItemMonthly As New ListItem("Monthly", "12")
ListItemMonthly.Attributes.Add("onmouseover", "ddrivetip('Example: $300 total amount paid monthly means 12 payments of $25.')")
ListItemMonthly.Attributes.Add("onmouseout", "hideddrivetip()")
RadioButtonListPaymentFrequency.Items.Add(ListItemMonthly)

Dim ListItemQuarterly As New ListItem("Quarterly", "4")
ListItemQuarterly.Attributes.Add("onmouseover", "ddrivetip('Example: $300 total amount paid quarterly means 4 payments of $75.')")
ListItemQuarterly.Attributes.Add("onmouseout", "hideddrivetip()")
RadioButtonListPaymentFrequency.Items.Add(ListItemQuarterly)

Dim ListItemSemiannually As New ListItem("Semiannually", "2")
ListItemSemiannually.Attributes.Add("onmouseover", "ddrivetip('Example: $300 total amount paid monthly means 2 payments of $150.')")
ListItemSemiannually.Attributes.Add("onmouseout", "hideddrivetip()")
RadioButtonListPaymentFrequency.Items.Add(ListItemSemiannually)

Generated HTML...

<table id="RadioButtonListPaymentFrequency" border="0">
    <tbody>
        <tr>
            <td>
                <input id="RadioButtonListPaymentFrequency_0" name="RadioButtonListPaymentFrequency" value="1" type="radio">
                <label for="RadioButtonListPaymentFrequency_0">One-Time Only</label>
            </td>
        </tr>
        <tr>
            <td>
                <input id="RadioButtonListPaymentFrequency_1" name="RadioButtonListPaymentFrequency" value="12" type="radio">
                <label for="RadioButtonListPaymentFrequency_1">Monthly</label>
            </td>
        </tr>
        <tr>
            <td>
                <input id="RadioButtonListPaymentFrequency_2" name="RadioButtonListPaymentFrequency" value="4" type="radio">
                <label for="RadioButtonListPaymentFrequency_2">Quarterly</label>
            </td>
        </tr>
        <tr>
            <td>
                <input id="RadioButtonListPaymentFrequency_3" name="RadioButtonListPaymentFrequency" value="2" type="radio">
                <label for="RadioButtonListPaymentFrequency_3">Semiannually</label>
            </td>
        </tr>
    </tbody>
</table>
+1  A: 

You don't. Unless you use a workaround, or subclass RadioButtonList. I'd personally just use JQuery to attach the event handlers.

Mark Brackett
A: 

Checkout: msdn.microsoft.com/en-us/library/b3se8ewc.aspx