Link to home
Start Free TrialLog in
Avatar of zolmedia
zolmedia

asked on

How to call function for radiobuttonlist's DataTextField attribute?

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">
  </asp:RadioButtonList>

(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.
Avatar of NazoUK
NazoUK
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
Avatar of zolmedia
zolmedia

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of NazoUK
NazoUK
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial