i want to create advence search but i have problem to get RadioButton Value and DataPicker Value .
this is my Xml Code :
<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"/>
how can i solve this problem ?
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;
}
show me this error when i using this code for compate to date
Edit
When i Use The RadioButton Show me this Error
bool Active;
if (Rad_Active.IsChecked) // Error 1 here
{
Active = true;
}
else if (Rad_DeActive.IsChecked) // Error 1 here
{
Active = false;
}
Error 1
Cannot implicitly convert type "bool?" to "bool".
DateTime Date = DateEndPicker.SelectedDate; // Error 2 here
Error 2
Cannot implicitly convert type 'Arash.PersianDate' to 'System.DateTime'
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
Error 3
Severity Code Description Project File Line Suppression State Error CS0019 Operator '>=' cannot be applied to operands of type 'DateTime' and 'PersianDate' AnbarDari F:\\MyProject\\AnbarDari\\AnbarDari\\Win_Users.xaml.cs 77 Active
Look into just one radio button. Just set bool? Active = Rad_Active.IsChecked
bool? Active = Rad_Active.IsChecked
This will set your active flag based on the status of that single checkbox.
As IsChecked
is a nullable bool you can't just do a straight cast. If it's null the cast will fail. Instead you can do this:
if (Rad_Active.IsChecked == true)
{
Active = true;
}
As for converting between a PerisanDate
and a regular DateTime
there will be a method or property that returns a regular DateTime
, but without knowing exactly which picker you are using it's hard to give a definitive answer. The IDE should be able to give you some clues via autocomplete or viewing the definition of the class (in Visual Studio, right click -> Go to definition)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.