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"
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"
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
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
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. RadioButto nList' in this class.
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.
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.
I no longer get the error, but still don't get the text.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, this was very helpful. Thank you.
SELECT "Description: " + table1.description....