[英]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.