gpt4 book ai didi

c# - 找不到类型 'MyType' 的默认成员

转载 作者:行者123 更新时间:2023-12-01 11:07:31 25 4
gpt4 key购买 nike

我正在使用 ObjectDataSource 将对象绑定(bind)到 GridView。在 OnRowDataBound 事件处理程序中,我试图确定某个按钮是否应该可见。当运行时遇到此语句时,它会触发“未找到类型‘保证’的默认成员”。错误:

lbDel.Visible = Not (e.Row.DataItem("BillingReady"))

绑定(bind)到 GridView 的我的对象类:

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);
}
}

我的 promise 类:

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#,但我认为这不是问题所在。如果我理解 C# 等效于 VB 默认属性,则称为索引器。这不应该有资格作为索引器吗?

public Pledge this[int index]
{
get { return ((Pledge)(List[index])); }
set { List[index] = value; }
}

最佳答案

尝试将 DataItem 转换为 Pledge:

Dim pledge = DirectCast(e.Row.DataItem, Pledge)
lbDel.Visible = Not pledge.BillingReady

关于c# - 找不到类型 'MyType' 的默认成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10020069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com