2012-04-04 6 views
1

私はObjectDataSourceを使用してオブジェクトをGridViewにバインドしています。 OnRowDataBoundイベントハンドラで、特定のボタンを表示するかどうかを判断しようとしています。ランタイムがこの文に遭遇すると、「Pledge '型のデフォルトメンバーが見つかりません」というメッセージが表示されます。エラー:'MyType'タイプのデフォルトメンバーが見つかりません

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

マイObjectクラスの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); 
    } 
} 

私の誓約クラス:

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; } 
} 
+0

[ASP.NETリピーターエラー:xxタイプの既定のメンバーが見つかりません](http://stackoverflow.com/questions/9673445/asp-net-repeater-error-no-default-member-found- for-type-xx) –

答えて

5

PledgeDataItemをキャストしてみます:

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

それはそれをしました!ありがとう。 – BKahuna

1

VBのDataGridにC#のモデルを結合するとき、私はこの同じ問題を抱えていました。

は、通常のaspxファイルでは、DataGridがでテンプレート列のフィールドを表示していました:

 <asp:templatecolumn headertext="Reference"> 
      <itemtemplate> 
       <%# Container.DataItem("Reference")%> 
      </itemtemplate> 
     </asp:templatecolumn> 

しかし、私のC#のモデルを使用した場合、DataGridがのテンプレート列の構文必要があります。

 <asp:templatecolumn headertext="Reference"> 
      <itemtemplate> 
       <%# DataBinder.Eval(Container.DataItem, "Reference") %> 
      </itemtemplate> 
     </asp:templatecolumn> 

これは分かりにくい問題だったので、これで答えが分かると時間を節約するのに役立ちます。

関連する問題