我有以下過程,它工作正常。我遇到問題的唯一部分是當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