我有以下程序,效果很好。我遇到的唯一问题是CompNames 列表有超过 1 条记录。我正在尝试将String.Join与 vbCrLf 一起使用,但它不起作用。
任何人都有任何想法或我可以使用的替代方案。
Public Sub gvTeamList_OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
Dim TeamID As Integer
If e.Row.RowType = DataControlRowType.DataRow Then
TeamID = DataBinder.Eval(e.Row.DataItem, "TeamID")
Dim sSQL As String
sSQL = "SELECT C.CompetitionName, CTT.TeamID " & _
"FROM tblCompetition C " & _
"left join tblCompetitionToTeam CTT on C.CompetitionID = CTT.CompetitionID " & _
"left join tblTeam T on CTT.TeamID = T.TeamID " & _
"where CTT.TeamID = " & TeamID
Dim dr = DataClass.GetDataReader(sSQL)
Dim bRows As Boolean = dr.HasRows
Dim CompNames As New List(Of String)
While dr.Read
CompNames.Add(dr("CompetitionName"))
End While
Dim Name As String
If CompNames.Count > 0 Then
For Each Name In CompNames
e.Row.Cells(5).Text = String.Join(vbCrLf, CompNames.ToArray)
Next
End If
'e.Row.Cells(5).Text =
e.Row.Cells(5).ForeColor = Drawing.Color.Yellow
e.Row.Cells(5).BackColor = Drawing.Color.DarkBlue
dr.Close()
End If
End Sub
我也尝试过Environment.NewLine但这也不起作用