Link to home
Start Free TrialLog in
Avatar of sl1nger
sl1nger

asked on

.net radiobuttonlist add text on databind

I need to add some text to a databind.
What I have...

Dim cmd2 As New SqlCommand(strQuery2, con)
            Dim da2 As New SqlDataAdapter(cmd2)
            Dim dtRF2 As New DataTable
            da2.Fill(dtRF2)

            lst_conn2.DataSource = dtRF2
            lst_conn2.DataTextField = "display_description"
            lst_conn2.DataValueField = "value"
            lst_conn2.DataBind()

I'd like to display more than just the data on textfield...  I'm trying to do something like this...

lst_conn2.DataTextField = Here's the decription: "display_description"
Avatar of pollock_d
pollock_d

you could always just changed your sql select to append "Description: " to the beginning of the column...

SELECT "Description: " + table1.description....
You can add an ondatabinding event and add the text to each button in that event.
You can modify the items after the data has been bound to it, add this to your code behind, basically it loops through all the items in the radio list and adds extra text to the text already there:

Protected Sub lst_conn2(ByVal sender As Object, ByVal e As System.EventArgs) Handles lst_conn2.DataBound
        For Each item As ListItem In lst_conn2.Items
            item.Text = "Here's the decription:  " & item.Text
        Next
    End Sub
Avatar of sl1nger

ASKER

NazoUK -
It looks close, but I get this error??
Compiler Error Message: BC30260: 'lst_conn2' is already declared as 'Protected Dim WithEvents lst_conn2 As System.Web.UI.WebControls.RadioButtonList' in this class.
Avatar of sl1nger

ASKER

I changed it to this.    Sub lst_conn2DataBound(ByVal sender As Object, ByVal e As RadioButtonList)

I no longer get the error, but still don't get the text.
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
Avatar of sl1nger

ASKER

Yes, this was very helpful.  Thank you.