We help IT Professionals succeed at work.

How to call function for radiobuttonlist's DataTextField attribute?

zolmedia asked
Last Modified: 2013-11-26
I want to modify the text displayed for a databound radiobutton, so that each item is proceeded with A), B), and so on.

I assumed I could just call a function to do this (as I've done w/ templated databound controls in the past, like this:
(in the .ASPX file)
  <asp:RadioButtonList ID="RadioButtonList3" runat="server" DataSourceID="SqlDataSource1"
    DataTextField='<%# AppendOrderedLetter(CType(Container.DataItem, System.Data.DataRowView)) %> ' DataValueField="AnswerID">

(in the .VB file)
  Function AppendOrderedLetter(ByRef row As System.Data.DataRowView) As String
    Dim strAnswer As String = row.Item("AnswerText")
    i += 1
    Dim strChr As String = Chr(i)
    strAnswer = strChr & ".) " & strAnswer
    Return strAnswer
  End Function

However, this throws the error: Compiler Error Message: BC30456: 'DataItem' is not a member of 'System.Web.UI.Page'.

I assume this is because the radio button isn't a "normal" templated control. How can achieve calling a function to create the DataTextField?

Note: I don't want to use the RadioButtonList3_DataBound event, because the radiobutton is nested within a formview, and I assume drilling down to it with the FindControl will be complicated.
Watch Question

I think using DataBound is going to be the best option. The sender parameter in the function delegate for the event is the control that raised the event. So if you cast the sender variable to be a RadioButtonList you can work directly with your control without having to drill directly into the control hierarchy.


NazoUK, bypassing the control hierarchy would be wonderful!

Theoritically I'm mostly following your explanation of how to do this, but am lost on how the details of how to actually do so. Can you provide a couple of snippets of how to do so though?
This one is on us!
(Get your first solution completely free - no credit card required)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.