我正在使用 ObjectDataSource 将对象绑定到 GridView。在 OnRowDataBound 事件处理程序中,我试图确定某个按钮是否应该可见。当运行时遇到此语句时,它会触发“No default member found for type 'Pledge'”。错误:
lbDel.Visible = Not (e.Row.DataItem("BillingReady"))
我绑定到 GridView 的 Object 类:
public class Pledges : System.Collections.CollectionBase
{
public Pledge this[int index]
{
get { return ((Pledge)(List[index])); }
set { List[index] = value; }
}
public int Add(Pledge pledge)
{
return List.Add(pledge);
}
}
我的承诺课:
public class Pledge
{
public int PledgeID { get; set; }
public int EventID { get; set; }
public int SponsorID { get; set; }
public int StudentID { get; set; }
public decimal Amount { get; set; }
public string Type { get; set; }
public bool IsPaid { get; set; }
public string EventName { get; set; }
public DateTime EventDate { get; set; }
public bool BillingReady { get; set; }
public string SponsorName { get; set; }
public int Grade_level { get; set; }
public string StudentName { get; set; }
public string NickName { get; set; }
public int Laps { get; set; }
public decimal PledgeSubtotal { get; set; }
}
我的 OnRowDataBound 事件处理程序:
Protected Sub PledgeGrid_OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If (e.Row.RowType = DataControlRowType.DataRow) And _
Not ((e.Row.RowState = DataControlRowState.Edit) Or ((e.Row.RowState = DataControlRowState.Alternate) And (e.Row.RowState = DataControlRowState.Edit))) Then
Dim lbDel As LinkButton
Dim lbEd As LinkButton
lbDel = CType(e.Row.FindControl("lbDelete"), LinkButton)
lbEd = CType(e.Row.FindControl("lbEdit"), LinkButton)
If ((e.Row.RowState = DataControlRowState.Normal) Or (e.Row.RowState = DataControlRowState.Alternate)) Then
lbDel.Visible = Not (e.Row.DataItem("BillingReady")) '<-- Problem happens here
lbEd.Visible = Not (e.Row.DataItem("BillingReady"))
End If
End If
End Sub
是的,我不得不混合使用 VB 和 C#,但我认为这不是问题所在。如果我理解 VB 默认属性的 C# 等效项称为索引器。这不应该有资格作为索引器吗?
public Pledge this[int index]
{
get { return ((Pledge)(List[index])); }
set { List[index] = value; }
}