我有以下对象:

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

}

我正在使用ASP.NET 3.5中的GridView构建动态串扰网格

我希望将动态列1的CellContents [0]结合,用于动态列2的CellContents [1](动态列0是CrosstabdataObject的Rowname字段)等。我正在使用:

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

该代码在GridView的启示素函数中,因为我在Crosstab的每个单元格中创建下拉列表模板。

我的代码(未显示)根据正在创建的列来设置strselectedID。

当strselectedID等于动态列[0] databinder.eval函数正常工作并按预期设置boundvalueobj时,strselectedID等于“ rowname”。当将strselectedID设置为“ cellcontents [n])时,问题出现在其中n是列索引。

databinder.eval仅适用于对象的属性和字段。我该如何解决?

谢谢,

富有的。

有帮助吗?

解决方案

好的 - 我愚蠢的错误!

更改:

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成为一类的属性。

富有的。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top