1

I have this simple WPF window below, the textbox is bound to a StudentName column in a table called Students, in XAML. I'm using EntityFramework 5 for data access.

Now you see this window when you run it, how do I got about implementing the Next and Previous buttons? I have looked online and paging has been suggested, but isn't there a simple one-line way, similar to the oldschool way of moving the recordset to new row? I don't want to use a datagrid, I need to have a bunch of text boxes later-on on the screen with the ability to press next and previous for browsing.

Even if there isn't a one-line way ( and I don't think there is ) just how do I implement the Next and Previous functionality ?

Thank you :)

enter image description here

This is my codebehind

        public LinqNext()
        {
            InitializeComponent();
            SchoolEntities schoolEntities = new SchoolEntities();
            MyGrid.DataContext = schoolEntities.Students.ToList();
        }

        private void NextButton_Click(object sender, RoutedEventArgs e)
        {
            //What do put here to move to next record
            //(Note this code is obviously "MVVM-FREE"
            //Right now i'd just like to move to next record
        }

This is My XAML ( simplified)

<Grid x:Name="MyGrid">
        <Button x:Name="NextButton" Content="Next" />
        <Button x:Name="PreviousButton" Content="Previous"/>
        <TextBox x:Name="StudentName" Text="{Binding Path=StudentName}" />
    </Grid>
4

1 回答 1

4

First you need to keep current student Id, then:

  var next = schoolEntities.Students.FirstOrDefault(x => x.Id > currentId);
  this.StudentName.Text = next.StudentName;
于 2013-07-14T12:53:32.760 回答