分页查询操作

                                     分页查询操作

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

开发工具与关键技术:Visual Studio 2015 * SQL Server

作者:

撰写时间:2019年01月01日

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

不管是MVC还是WPF中都不会少分页操作按钮的使用,一般拿它来查询数据,分页操作按钮为了更快的查询出数据,

    private void btn_Select_Click(object sender, RoutedEventArgs e)

        {

            dtStationManage = ChaXunShuJu(intPageSize, intPageIndex, false, true);

            dgStationManage.ItemsSource = dtStationManage.AsDataView();

            if (dtStationManage.Rows.Count < 1)

            {

                intPageIndex = 0;

                txtCurrentPage.Text = "0";

                cboPageLineCount.IsEnabled = false; 

                txtCurrentPage.IsEnabled = false; 

            }

            else

            {

                cboPageLineCount.IsEnabled = true;

                txtCurrentPage.IsEnabled = true;

            }

            UpdatePagingButton();

        }

 

首页、上一页、下一页和尾页的做法,页面一加载时,首页和上一页的按钮为禁用状态,当当前页已是表格的最大页时,下一页和尾页为禁用状态。

            private void imgMostUp_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)

        {

     

            if (((Image)sender).Opacity == 1)

            {

                intPageIndex = 1; 

                txtCurrentPage.Text = "1"; 

                btn_Select_Click(null, null);

            }

        }

                private void imgUp_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

        {

                        if (((Image)sender).Opacity == 1)

            {

                intPageIndex--;

                txtCurrentPage.Text = intPageIndex.ToString();

                btn_Select_Click(null, null);

            }

        }

       首页,上一页和下一页、尾页写法基本一样,先定义一个点击事件,在用if判断,((Image)sender).Opacity == 1,就当前索引+1,设置文本值显示当前页,在调用查询方法。

 

  private void cboPageLineCount_SelectionChanged(object sender, SelectionChangedEventArgs e)

        {

            intPageSize = Convert.ToInt32(cboPageLineCount.SelectedValue);

            intPageIndex = 1;

            

            btn_Select_Click(null, null);

        }

       

        private void txtCurrentPage_TextChanged(object sender, TextChangedEventArgs e)

        {

            TextBox textBox = sender as TextBox;

            TextChange[] change = new TextChange[e.Changes.Count];

            e.Changes.CopyTo(change, 0);

            int offset = change[0].Offset;

            if (change[0].AddedLength > 0)

            {

                int num = 0;

                if (!int.TryParse(textBox.Text, out num))

                {

                    textBox.Text = textBox.Text.Remove(offset, change[0].AddedLength).ToString().Trim();

                    textBox.Select(offset, 0);

                }

            }

            if (decPageCount != 0)

            {

                if (Convert.ToInt32(textBox.Text.Trim()) > decPageCount)

                {

                    textBox.Text = decPageCount.ToString();

                }

                else if (Convert.ToInt32(textBox.Text.Trim()) < 1)

                {

                       textBox.Text = "1";

                }

            }

            

            if (intPageIndex != Convert.ToInt32(textBox.Text.Trim()) && Convert.ToInt32(textBox.Text.Trim()) >= 1)

            {

                intPageIndex = Convert.ToInt32(textBox.Text.Trim());

                btn_Select_Click(null, null);

            }

        }

               

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值