[英]How do I use RowFilter to to find the length of the longest string in a column?
[英]How to retrieve object Column from DataSource RowFilter
我目前正在尝试从数据表中检索包含某些对象列中包含对象的列的列。
让我们看看 :
(this.CohortGrid.DataSource as DataTable).DefaultView.RowFilter = string.Format("CohortFormation.Name LIKE '*{0}*'", ddlFormation.SelectedItem.Text);
我将这些列放入DataTable中:
[0]:ID
[1]:姓名
[2]:状态
[3]:同类群组
[4]:RoomCol
[5]:讲师颜色
[6]:EmployeeCol
CohortFormation列是一个包含ID和Name的对象。
所以,我试图找回CohortFormation这样的名称CohortFormation.Name LIKE
但它返回我:
找不到列
在网格视图TemplateField中,我可以执行<%# Eval("CohortFormation.Name") %>
,并且效果很好。 但是在后面的代码中我该怎么做?
我刚刚找到了一个解决方案,并且效果很好!
我遍历DataTable并删除不等于在DropDownList-> ddlFormation中选择的值的行。
有代码:
CohortCollection cohortCol = (CohortCollection)Session["cohortCol"];
foreach(Cohort cohort in cohortCol.ToList())
{
if(cohort.Status.Id != int.Parse(ddlFormation.SelectedItem.Value))
{
cohortCol.Remove(cohort);
}
}
this.CohortGrid.DataSource = cohortCol;
this.CohortGrid.DataBind();
因此,诀窍是在列表而不是DataTable上循环,如果不相等,则删除该对象。 最后,我们绑定数据。
它完美地工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.