Aditya Patil

Aditya Patil

  • NA
  • 535
  • 134.1k

Set value to Datepicker and Listpicker from SQLITE DB

Jul 21 2014 1:55 AM
I am writing code for fetching the data from the SQLITE database to the Controls those added on the Windows Phone Application page.
In my page there is one TextBox, DatePicker & Listpicker, from SQLITE query I am getting data but it only shows in the TextBox field only, not shown in other controls like DatePicker and ListPicker.
 
Xaml CODE:
<toolkit:DatePicker Name="dpkDate" Margin="0,144,0,332" />
<toolkit:ListPicker x:Name="priority" Margin="10,233,10,188" ExpansionMode="ExpansionAllowed" Background="#FFF7EBEB" SelectedIndex="2">
<ListBoxItem x:Name="high" Content="High" Foreground="Black"/>
<ListBoxItem x:Name="medium" Content="Medium" Foreground="Black"/>
<TextBox HorizontalAlignment="Left" Height="134" Margin="0,5,0,0" TextWrapping="Wrap" Text="Wrpite Note" VerticalAlignment="Top" Width="456" Name="TextField"/> 
 
.CS CODE
protected override void OnNavigatedTo(NavigationEventArgs e)
dbConn = new SQLiteConnection(DB_PATH); // Create the table Task, if it doesn't exist.
dbConn.CreateTable<Task>(); // Retrieve the task list from the database.

try
{
string id = NavigationContext.QueryString["selectedItem"].ToString(); //this retrive the index of selected item from ListBox which on previous page

var note= dbConn.Query<Task>("select * from task where Id='" + id + "'").FirstOrDefault(); //use that index as ID of the table
if (note == null)
MessageBox.Show("Not Present in DataBase");
else
{
TextField.Text = note.Text; //Its working fine, the selected index value shown here
dpkDate.Value = DateTime.Parse(note.Text); //not working
((ListBoxItem)priority.SelectedItem).Content = note.Text; //not working
}
}

Where I am wrong? Please help.

Answers (12)