BKa*_*una 2 c# vb.net gridview
我正在使用ObjectDataSource将对象绑定到GridView.在OnRowDataBound事件处理程序中,我正在尝试确定某个按钮是否应该可见.当运行时遇到此语句时,它会触发"找不到类型'Pledge'的默认成员." 错误:
lbDel.Visible = Not (e.Row.DataItem("BillingReady"))
Run Code Online (Sandbox Code Playgroud)
绑定到GridView的My 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);
}
}
Run Code Online (Sandbox Code Playgroud)
我的承诺课程:
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; }
}
Run Code Online (Sandbox Code Playgroud)
我的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
Run Code Online (Sandbox Code Playgroud)
是的,我不得不混合VB和C#,但我不认为这是问题所在.如果我理解VB默认属性的C#等价物被称为索引器.这不应该有资格作为索引器吗?
public Pledge this[int index]
{
get { return ((Pledge)(List[index])); }
set { List[index] = value; }
}
Run Code Online (Sandbox Code Playgroud)
尝试投射DataItem
到Pledge
:
Dim pledge = DirectCast(e.Row.DataItem, Pledge)
lbDel.Visible = Not pledge.BillingReady
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5069 次 |
最近记录: |