Kianoush Kianoush - 1 year ago 99
C# Question

get Value DataPicker and Radio Button

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


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".

Edit 2

DateTime Date = DateEndPicker.SelectedDate; // Error 2 here

Error 2

Cannot implicitly convert type 'Arash.PersianDate' to 'System.DateTime'

Edit 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

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

Answer Source

Look into just one radio button. Just set bool? Active = Rad_Active.IsChecked This will set your active flag based on the status of that single checkbox.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download