locked
分页的问题 RRS feed

  • 问题

  • 我用RiA service做公司的薪资报表,用datagrid+DomainDataSource+DataPager分页,在datagrid下部加了个textbox用于显示分页时的工资总额,现在发现二个问题:

    (1)页面进入时,未发生翻页前,如何计算当前页的工资总额呢?
    (2)翻页时,我老是得到上一页的工资总额,问题出现在哪里?

            private void dataPager1_PageIndexChanged(object sender, EventArgs e)

            {
                int total = 0;
                foreach (object o in DataGrid1.ItemsSource)
                {
                    PriceTable _PriceTable = o as PriceTable;
                    total += _PriceTablee.Moneys;

                }
                this.textBlock1.Text = total.ToString();//这里得到的是上一页的工资总额???
            }

    请各位大大帮忙,最好有代码参考,这里我先谢谢大家了。

    • 已编辑 xmf16 2010年7月5日 4:19
    2010年7月1日 10:04

答案

  • 你好,

          你可以用这个:
               <sdk:DataGrid x:Name="dg" AutoGenerateColumns="False">
                        <sdk:DataGrid.Columns>
                            <sdk:DataGridTemplateColumn>
                                <sdk:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBox Text="{Binding UnitPrice}"></TextBox>
                                    </DataTemplate>
                                </sdk:DataGridTemplateColumn.CellTemplate>
                            </sdk:DataGridTemplateColumn>
                        </sdk:DataGrid.Columns>
                    </sdk:DataGrid>
                    <TextBlock x:Name="price"></TextBlock>
                    <sdk:DataPager Source="{Binding ItemsSource,ElementName=dg}" PageIndexChanged="DataPager_PageIndexChanged" PageSize="10">
              </sdk:DataPager>

            DataBaseContext dbc = new DataBaseContext();
            PagedCollectionView pcv;
            public Home()
            {
                InitializeComponent();
                this.Title = ApplicationStrings.HomePageTitle;
                dbc.Load<Track>(dbc.GetTrackQuery(), Home_Completed, false);
               
            }


            void Home_Completed(LoadOperation lo)
            {
                pcv = new PagedCollectionView(dbc.Tracks);
                dg.ItemsSource = pcv;
            }

            private void DataPager_PageIndexChanged(object sender, System.EventArgs e)
            {
                decimal res = 0;
                foreach (Track it in dg.ItemsSource) {
                    res = it.UnitPrice + res;
                }
                price.Text = res.ToString();
            }

    • 已标记为答案 xmf16 2010年7月5日 4:20
    2010年7月5日 2:48

全部回复

  • 你好,

          你可以用这个:
               <sdk:DataGrid x:Name="dg" AutoGenerateColumns="False">
                        <sdk:DataGrid.Columns>
                            <sdk:DataGridTemplateColumn>
                                <sdk:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBox Text="{Binding UnitPrice}"></TextBox>
                                    </DataTemplate>
                                </sdk:DataGridTemplateColumn.CellTemplate>
                            </sdk:DataGridTemplateColumn>
                        </sdk:DataGrid.Columns>
                    </sdk:DataGrid>
                    <TextBlock x:Name="price"></TextBlock>
                    <sdk:DataPager Source="{Binding ItemsSource,ElementName=dg}" PageIndexChanged="DataPager_PageIndexChanged" PageSize="10">
              </sdk:DataPager>

            DataBaseContext dbc = new DataBaseContext();
            PagedCollectionView pcv;
            public Home()
            {
                InitializeComponent();
                this.Title = ApplicationStrings.HomePageTitle;
                dbc.Load<Track>(dbc.GetTrackQuery(), Home_Completed, false);
               
            }


            void Home_Completed(LoadOperation lo)
            {
                pcv = new PagedCollectionView(dbc.Tracks);
                dg.ItemsSource = pcv;
            }

            private void DataPager_PageIndexChanged(object sender, System.EventArgs e)
            {
                decimal res = 0;
                foreach (Track it in dg.ItemsSource) {
                    res = it.UnitPrice + res;
                }
                price.Text = res.ToString();
            }

    • 已标记为答案 xmf16 2010年7月5日 4:20
    2010年7月5日 2:48
  • 你好,

          你可以用这个:
               <sdk:DataGrid x:Name="dg" AutoGenerateColumns="False">
                        <sdk:DataGrid.Columns>
                            <sdk:DataGridTemplateColumn>
                                <sdk:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBox Text="{Binding UnitPrice}"></TextBox>
                                    </DataTemplate>
                                </sdk:DataGridTemplateColumn.CellTemplate>
                            </sdk:DataGridTemplateColumn>
                        </sdk:DataGrid.Columns>
                    </sdk:DataGrid>
                    <TextBlock x:Name="price"></TextBlock>
                    <sdk:DataPager Source="{Binding ItemsSource,ElementName=dg}" PageIndexChanged="DataPager_PageIndexChanged" PageSize="10">
              </sdk:DataPager>

            DataBaseContext dbc = new DataBaseContext();
            PagedCollectionView pcv;
            public Home()
            {
                InitializeComponent();
                this.Title = ApplicationStrings.HomePageTitle;
                dbc.Load<Track>(dbc.GetTrackQuery(), Home_Completed, false);
               
            }


            void Home_Completed(LoadOperation lo)
            {
                pcv = new PagedCollectionView(dbc.Tracks);
                dg.ItemsSource = pcv;
            }

            private void DataPager_PageIndexChanged(object sender, System.EventArgs e)
            {
                decimal res = 0;
                foreach (Track it in dg.ItemsSource) {
                    res = it.UnitPrice + res;
                }
                price.Text = res.ToString();
            }


    首先感谢小唐版主的回复。只是感觉我的问题仍然存在:

    1.  我要求是用“DomainDataSource+DataPager分页”。
    2.  版主的的案例分页性能不佳,好象是把数据全取出来才分页的吧?

    小唐版主能否给我一个DomainDataSource+DataPager分页时footer进行统计的例子呢?谢谢

    2010年7月5日 3:15