.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"
sl1ngerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
NazoUKConnect With a Mentor Commented:
Whoops my apologies, that code should read:

Protected Sub lst_conn2_DataBound(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

If you update this does it work?
0
 
pollock_dCommented:
you could always just changed your sql select to append "Description: " to the beginning of the column...

SELECT "Description: " + table1.description....
0
 
Bane83Commented:
You can add an ondatabinding event and add the text to each button in that event.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
NazoUKCommented:
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
0
 
sl1ngerAuthor Commented:
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.
0
 
sl1ngerAuthor Commented:
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.
0
 
sl1ngerAuthor Commented:
Yes, this was very helpful.  Thank you.
0
All Courses

From novice to tech pro — start learning today.