我想要创建高级搜索,但是我在获取RadioButton值和DataPicker值方面有问题。
这是我的Xml代码:
<PersianDateControls:PersianDatePicker Name="DateEndPicker" HorizontalAlignment="Left" Margin="32,470,0,0" VerticalAlignment="Top" Width="115" Background="White" Height="25" Grid.Column="2"/>
<PersianDateControls:PersianDatePicker Name="DateStartPicker" HorizontalAlignment="Left" Margin="32,418,0,0" VerticalAlignment="Top" Width="115" Background="White" Grid.Column="2"/>
<RadioButton x:Name="Rad_Active" Content="Active" IsChecked="True" HorizontalAlignment="Left" Margin="407,433,0,0" VerticalAlignment="Top" Foreground="White" FontFamily="Iranian Sans"/>
<RadioButton x:Name="Rad_DeActive" Content="DeActive" HorizontalAlignment="Left" Margin="272,433,0,0" VerticalAlignment="Top" Foreground="White" FontFamily="Iranian Sans"/>我该如何解决这个问题?
private void btn_search_MouseDown(object sender, MouseButtonEventArgs e)
{
string Name = txt_Name.Text;
string Family = txt_family.Text;
var QSearch = db.Tbl_User.Where(u => u.Name == Name).Where(u => u.Family == Family).ToList();
dataGrid.ItemsSource = QSearch;
}将此代码用于compate时,请向我显示此错误
编辑
当我使用RadioButton时,向我显示这个错误
bool Active;
if (Rad_Active.IsChecked) // Error 1 here
{
Active = true;
}
else if (Rad_DeActive.IsChecked) // Error 1 here
{
Active = false;
}错误1
不能隐式转换类型"bool?“变成“嘘声”。
编辑2
DateTime Date = DateEndPicker.SelectedDate; // Error 2 here误差2
不能隐式地将“Arash.PersianDate”转换为“System.DateTime”
编辑3
PersianDate DateEnd = DateEndPicker.SelectedDate;
PersianDate DateStart = DateEndPicker.SelectedDate;
var QSearch = db.Tbl.User.Where(u => u.Name == Name)
.Where(u => u.Family == Family)
.Where(u => u.Active == Active)
.Where(u => u.DateReg >= DateStart && u.DateReg <= DateEnd).ToList(); // Error 3 here
dataGrid.ItemsSource = QSearch错误3
严重性代码描述项目文件行抑制状态错误CS0019操作符'>=‘不能应用于'DateTime’和'PersianDate‘AnbarDari AnbarDari 77活动的操作数
发布于 2016-10-14 20:22:37
只看一个单选按钮。只需设置bool? Active = Rad_Active.IsChecked,这将根据单个复选框的状态设置活动标志。
发布于 2016-10-14 20:38:37
由于IsChecked是一个可空的bool,所以您不能只做一个直接的转换。如果它为空,则转换将失败。相反,您可以这样做:
if (Rad_Active.IsChecked == true)
{
Active = true;
}至于在PerisanDate和普通DateTime之间的转换,会有一个返回常规DateTime的方法或属性,但是不知道您使用的是哪个选择器,很难给出一个明确的答案。IDE应该能够通过自动完成或查看类的定义提供一些线索(在Visual中,右键单击->转到definition)
https://stackoverflow.com/questions/40051018
复制相似问题