我想选择要在报告中显示的列,使用以下代码:
Database1Entities DBE = new Database1Entities();
string FirstName = "";
string LastName = "";
if (checkBoxFirstName.IsChecked == true)
FirstName = "c.First_Name";
if (checkBoxLastName.IsChecked == true)
LastName = "c.Last_Name";
var search = from c in DBE.Tables
where
string.IsNullOrEmpty(textBoxFirstName.Text) || (textBoxFirstName.Text) == (c.First_Name)
&&
string.IsNullOrEmpty(textBoxLastName.Text) || (textBoxLastName.Text) == (c.Last_Name)
select new { FirstName, LastName };
dataGrid.ItemsSource = search.ToList();
但结果是:
在上面的代码中,我使用了两个变量FirstName
和LastName
。如果选中该复选框,则在要显示的报告中,但不起作用。