我正在尝试过滤我的数据源中的数据,该数据源以datalist格式打印。我知道如何使用datalist,这是没有问题的。问题在于过滤。
我试过这个:
DataSet ds = (DataSet)Application["Products"];
DataSet newDS = new DataSet();
newDS.Tables.Add("products");
DataRow[] DR = ds.Tables[0].Select("CategoryID='" + this.CategoryID + "'");
for (int i = 0; i < DR.Length; i++)
newDS.Tables[0].ImportRow(DR[i]);
PagedDataSource PDS = new PagedDataSource();
PDS.DataSource = newDS.Tables[0].DefaultView;
PDS.AllowPaging = true;
PDS.PageSize = 9;
PDS.CurrentPageIndex = CurrentPage;
this.DataList_Products.DataSource = PDS;
this.DataList_Products.DataBind();在那之后,我收到了这个问题:
DataBinding:“System.Data.DataRowView”不包含名为“ProductID”.的属性
我确实有一个名为ProductID的属性,如何解决这个问题?
发布于 2012-04-03 17:57:48
也许我遗漏了什么,但看起来你的代码比你需要的要多。此外,您还应该利用LINQ实现以下功能:
this.DataList_Products.DataSource = ds.Tables[0].AsEnumerable().Where(r => r.Field<int>("CategoryID") == this.CategoryID).AsDataView().ToTable();
this.DataList_Products.DataBind();发布于 2012-04-03 17:22:52
新的dataset (及其datatable)没有原始数据集的结构。
DataSet ds = (DataSet)Application["Products"];
DataSet newDS = new DataSet();
DataTable newTable = ds.Tables[0].Clone();//this copies the structure
newDS.Tables.Add(newTable);https://stackoverflow.com/questions/9998188
复制相似问题