2010-09-03 17 views
0

列表 我有以下對象: 綁定使用的DataBinder.Eval

CrossTabDataObject 
{ 
    string RowName{get;set;}; 
    int RowId{get;set;} 
    List<string> CellContents = new List <string>(); 
    //Constructor..... etc. 

} 

我建在asp.net使用的GridView 3.5

我希望綁定到CellContents動態交叉網格[0]用於動態塔1,CellContents [1]用於動態柱2(動態列0是從所述CrossTabDataObject字段RowName)等我使用:

object boundValueObj = null; 
Control ctrl = (Control)sender; 
IDataItemContainer dataItemContainer = (IDataItemContainer)ctrl.NamingContainer; 
boundValueObj = DataBinder.Eval(dataItemContainer.DataItem, strSelectedID); 

此代碼是在Gridview的InstantiateIn函數,因爲我在交叉表的每個單元格中創建了下拉列表模板。

我有代碼(未顯示),根據創建的列設置strSelectedID。

當strSelectedID等於動態列[0]的「RowName」時,DataBinder.Eval函數可以正常工作,並按預期設置boundValueObj。當strSelectedID設置爲「CellContents [n]」,其中n是列索引時出現問題。

DataBinder.Eval僅適用於對象的屬性和字段。我如何解決這個問題?

謝謝,

豐富。

回答

0

行 - 我犯的愚蠢的錯誤!

更改:

CrossTabDataObject 
{ 
    string RowName{get;set;}; 
    int RowId{get;set;} 
    List<string> CellContents = new List <string>(); 
    //Constructor..... etc. 

} 

到:

CrossTabDataObject 
{ 
    string RowName{get;set;}; 
    int RowId{get;set;} 
    List<string> CellContents{get;set;} 
    //Constructor 
    public CrossTabDataObject() 
    { 
    CellContents = new List<string>(); 
    } 

} 

使所有的差異。換句話說,我讓CellContents成爲這個類的一個屬性。

豐富。