我有以下过程,它工作正常。我遇到问题的唯一部分是当CompNames列表有多条记录时。我正在尝试使用String.Join与vbCrLf但它不起作用。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和不工作或者
定义“不起作用”。 – Oded 2013-02-12 13:39:17
您可以检查有关问题[here](http://www.dotnetperls.com/string-join) – spajce 2013-02-12 13:42:39
看起来这是一个'WebForms'应用程序,所以我添加了标签。请尝试在您的代码中包含有关应用程序环境(Windows应用程序与网页)的信息,因为这是一个重要的区别。 – mellamokb 2013-02-12 13:44:29