开发者

How to Add Text to a VB.NET RadioButtonList

I'm dynamically creating a RadioButtonList and can't figure out how to add additional text to show up under the radio button.

My basic code is as follows and I want sURL to show up under each resultant radio button.

For i As Integer = 0 To ds.Tables(0).Rows.Count - 1

                Dim iLocationID As Integer = ds.Tables(0).Rows(i).Item("LocationID")
                Dim sStreet As String = ds.Tables(0).Rows(i).Item("AddressStreet")
                Dim sCity As String = ds.Tables(0).Rows(i).Item("AddressCity")
                Dim sState As String = ds.Tables(0).Rows(i).Item("AddressState")
                Dim sZip As String = ds.Tables(0).Rows(i).Item("AddressPostalCode")
                开发者_如何学编程Dim sName as String = ds.Tables(0).Rows(i).Item("Name")
                Dim dsContact As New DataSet

                Dim sURL As String = ""
                sURL = "<a href='http://www.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=" & sStreet & "+" & sState & "+" & sZip & "' target='_blank'>" & sStreet & " " & sCity & " " & sState & ", " & sZip & "</a>"

                Dim dDistance As Decimal = Math.Round(ds.Tables(0).Rows(i).Item("Distance"), 1)
                Dim sDistance As String
                If dDistance > 1 Then
                    sDistance = dDistance & " Miles Away"
                Else
                    sDistance = dDistance & " Mile Away"
                End If
                sURL += " " & sDistance
                sURL += " Phone: " & sContactPhone

                rblVendorLocations.Items.Add(New ListItem(sName, iLocationID))
            Next


The first parameter to the ListItem constructor is the text to show beside the radio button, if you want that to be sURL then pass that rather than sName.

You can also pass html as this parameter if you want to style it in some particular way e.g.

ListDeliveryFrequency.Items.Add( _
              New ListItem("<div>" + sName +"</div> <div>" + sUrl + "</div>", _
                           iLocationID))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜