How I can filter a dataTable with Linq to datatable?

前端 未结 3 1561
执念已碎
执念已碎 2020-12-14 02:59

hi how i can filter a datatable with linq to datatable? I have a DropDownList and there I can select the value of the Modul Column. Now I want to filter the DataTable with

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 03:13

    You can use condition to check rows exist in addition before casting. System.Linq namespace is required for Any() to work

    var rows = values.AsEnumerable().Where
                (row => row.Field("Status") == action);//get the rows where the status is equal to action
    
    if(rows.Any())
    {
        DataTable dt = rows.CopyToDataTable();//Copying the rows into the DataTable as DataRow
    }
    

提交回复
热议问题