抱歉,我今天遇到错误
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: System.Web.UI.WebControls.DataControlFieldCollection must have items of type 'System.Web.UI.WebControls.DataControlField'. 'ItemTemplate' is of type 'System.Web.UI.HtmlControls.HtmlGenericControl'.
Source Error:
Line 66:
Line 67: <asp:TemplateField HeaderText="AS of" & label2.text>
Line 68: <ItemTemplate>
Line 69: <%#Getsales(Decimal.Parse(Eval("AsOFSales").ToString())).ToString("C0")%>
Line 70: </ItemTemplate>
答案 0 :(得分:1)
您无法在ASP.NET标记中使用VB.NET代码。如果要更改HeaderText,请在代码隐藏中执行此操作。
答案 1 :(得分:1)
正如TA先生所说,你需要从你的代码中做出这些改变。类似下面的代码 - 只需更换?在单元格(?)中使用网格中列号的(基于零的索引)(或w
Protected Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) handles DataGrid1.ItemDataBound
If (e.Item.ItemType = ListItemType.Header) Begin
e.Item.Cells(?).Text = "AS of" & label2.text
End If
End Sub
答案 2 :(得分:1)
你不能这样做:
Line 67: <asp:TemplateField HeaderText="AS of" & label2.text>
最好将其留空并在RowDataBound事件期间将其设置在后面的代码中。
Protected Sub myGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles myGridView.RowDataBound
If e.Row.RowType = DataControlRowType.Header Then
Dim e.Row.Cells(2).Text = "As of " & Label2.Text
End If
End Sub
这假设您没有在GridView上启用排序。如果确实启用了排序,则首先必须找到LinkButton控件并更改其文本值。我还在Cells标识符中使用了任意值2。您需要使用所需单元格的数字列号。