因此,對於任何人都好奇,這似乎是解決問題的辦法。
Private Sub grdMainGrid_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdMainGrid.RowCreated
If e.Row.RowType = DataControlRowType.Header Then
For Each itm As TableCell In e.Row.Cells
itm.Text = GenerateHeaderHTML()
Next
End If
End Sub
PS:如果任何人有任何更好的解決方案我很想聽到他們:-)
下面的代碼是我在GenerateHeaderHTML()。我的代碼是一個非常特殊的情況(並且很不錯)。但請注意,您可以使用任何您希望的html。
Private Sub grdMainGrid_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdMainGrid.RowCreated
If Me.BoundedObjects IsNot Nothing Then
If e.Row.RowType = DataControlRowType.Header Then
Dim PrimitivePropertyNames As List(Of String) = ParserHelper.GetPrimitivePropertyNames(Me.BoundedObjects.ToList)
Dim i As Integer = 0
For Each itm As TableCell In e.Row.Cells
itm.Text = ucStockImport.CreateBindingHeaderTable(itm.Text, PrimitivePropertyNames, i.ToString)
i += 1
Next
End If
Else
Throw New StockImportException("ucStockImport.BoundedObjects Is Nothing")
End If
End Sub
Private Shared Function CreateBindingHeaderTable(ByVal HeaderText As String, ByVal PropertyNames As List(Of String), ByVal ID As String) As String
Return String.Format("<table><tr><td>{0}</td></tr><tr><td>{1}</td></tr></table>", HeaderText, ucStockImport.CreateBindedObjectDropDownList(PropertyNames, ID))
End Function
Private Shared Function CreateBindedObjectDropDownList(ByVal PropertyNames As List(Of String), ByVal ID As String) As String
Dim strBuilder As New StringBuilder
strBuilder.Append(String.Format("<option value=""{0}"">{1}</option>", i, propName))
Dim i As Integer = 0
For Each propName As String In PropertyNames
strBuilder.Append(String.Format("<option value=""{0}"">", i) & propName & "</option>")
i += 1
Next
strBuilder.Append("</select>")
Return strBuilder.ToString
End Function
你可以發佈你的GenerateHeaderHTML方法的代碼嗎? – PhilPursglove 2010-07-28 08:40:17
請在上面找到該代碼... :-) – 2010-07-28 11:53:10