更新操作が必要な Windows Phone 7 アプリケーションを開発しています。次のテーブル クラスがあります。
[Table]
public class StudentTable
{
[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
public int StudentID
{
get;
set;
}
[Column (CanBeNull = false)]
public string StudentName
{
get;
set;
}
[Column(CanBeNull = false)]
public string StudentClass
{
get;
set;
}
[Column(CanBeNull = false)]
public DateTime regDate
{
get;
set;
}
}
次の方法で各生徒の値を取得しています..
using (StudentDataContext context = new StudentDataContext(strConnectionString))
{
StudentTable newStudent = new StudentTable
{
StudentName = textBox1.Text.ToString(),
StudentClass = textBox2.Text.ToString(),
regDate = ((DateTime) datePicker.Value).Date.Add(((DateTime)timePicker.Value).TimeOfDay)
};
context.StudentInfo.InsertOnSubmit(newStudent);
context.SubmitChanges();
}
学生をリストボックスに表示します....
<ListBox HorizontalAlignment="Left" Name="StudentlistBox1" ItemsSource="{Binding}" Loaded="StudentlistBox1_Loaded">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding StudentName}" FontSize="{StaticResource PhoneFontSizeLarge}"></TextBlock>
<TextBlock Text="{Binding StudentClass}" FontSize="{StaticResource PhoneFontSizeLarge}"></TextBlock>
<TextBlock Text="{Binding regDate}" FontSize="{StaticResource PhoneFontSizeSmall}"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
リストボックスで選択した各項目が、選択したレコードを更新できるページにつながるようにコーディングしようとしています。選択したアイテムの主キーを取得できれば、それができると思います...リストボックスで学生を選択し、その学生IDを渡すにはどうすればよいですか? どんなアイデアでも.....Windows Phone 7が初めてです..助けてください..