我正在开发一个需要更新操作的 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 的新手......请帮助......