亲密接触ASP.Net(14)

2016-01-29 19:18 1 1 收藏

亲密接触ASP.Net(14),亲密接触ASP.Net(14)

【 tulaoshi.com - ASP 】

  个性化分页(2)

上一节大家没有看到总的结构,这一节,我把代码全部贴出来,大家好好看看。

<%@ Page Language="C#" %
<%@ Import Namespace="System.Data" %
<%@ Import Namespace="System.Data.SQL" %
<html
<script language="C#" runat="server"

void Page_Load(Object sender, EventArgs e)
{
    //判断是否隐藏PagerStyle-Mode
    if (chk1.Checked)
    {
        MyDataGrid.PagerStyle.Visible=true;
    }
    else
    {
        MyDataGrid.PagerStyle.Visible=false;
    }

    BindGrid();
}

ICollection CreateDataSource()
{
    /*
        读取数据库的信息,获得DataView
    */
    SQLConnection MyConnection = new SQLConnection("server=localhost;uid=sa;pwd=123456;database=aspcn");
    SQLDataSetCommand MyDataSetCommand = new SQLDataSetCommand("select * from admin_enter order by Enter_Time desc",MyConnection);
    DataSet ds= new DataSet();
    MyDataSetCommand.FillDataSet(ds,"admin_enter");
    return ds.Tables["admin_enter"].DefaultView;
}

void PagerButtonClick(Object sender, EventArgs e)
{
    //获得LinkButton的参数值
    String arg = ((LinkButton)sender).CommandArgument;

    switch(arg)
    {
        case ("next"):
            if (MyDataGrid.CurrentPageIndex < (MyDataGrid.PageCount - 1))
            MyDataGrid.CurrentPageIndex ++;
            break;
        case ("prev"):
            if (MyDataGrid.CurrentPageIndex 0)
            MyDataGrid.CurrentPageIndex --;
            break;
        case ("last"):
            MyDataGrid.CurrentPageIndex = (MyDataGrid.PageCount - 1);
            break;
        default:
            //本页值
            MyDataGrid.CurrentPageIndex = arg.ToInt32();
            break;
    }
    BindGrid();
}

void MyDataGrid_Page(Object sender, DataGridPageChangedEventArgs e)
{
    //处理按下数字的方法
    BindGrid();
}

void BindGrid()
{
    //将DataView绑定到DataGrid上去
    MyDataGrid.DataSource = CreateDataSource();
    MyDataGrid.DataBind();
    ShowStats();
}

void ShowStats()
{
    //显示页面信息
    lblCurrentIndex.Text = "当前页数为: " + ((int)MyDataGrid.CurrentPageIndex+1);
    lblPageCount.Text = "总页数是: " + MyDataGrid.PageCount;
}

</script

<

来源:https://www.tulaoshi.com/n/20160129/1508998.html

延伸阅读
标签: ASP
  我们继续前面的内容,呵呵,这次主要是讲DataSet的强大功能啦:)。上次吹了大家的泡泡(说话不算数的意思,湖南人都能听懂吧:)),这次一定不能再食言了:) 在一个DataSet中储存多个数据表 我们在ASP中很多人习惯于使用RecordSet对象来操作数据库,但是RecordSet有一个的缺点就是一个RecordSet只能储存一个数据表,当我们需要操作...
标签: ASP
  在ASP.Net内中,如何做到分页 我不只一次地被别人问起,如何在ASP.Net实现分页功能。我实在不愿意回答这个问题。因为在ASP.Net中实现分页,实在是太简单了,简单到你一看到程序就会去气得跳楼,呵呵要发表感叹,为什么这个东东不早出来。 在以住的WEB技术中,我们要做到分页,经常是一长串代码才能搞定它,而且每用一个页面,就要重写...
标签: ASP
  上一节,我们简单的讲了一下数据库的应用,而我们没有具体说明执行语句如何用于显示。呵呵,是留在这一章节中讲的。这里我们必须得了解一下DataReader,DataSet和DataGrid控件,DataGrid是显示控件,大家自已去看它相关的应用,我们在这里不哆嗦,DataReader和DataSet都可以用来储存数据内容,不过DataReader只能储存查询的结果,DataSet...
标签: ASP
  不好意思,很久没有写文章,主要原因是前段时间考试,忙得飞刀我昏头转向,现在时间终于有多余了,所以不得不又提起笔来了(注:没有笔,回到家,连电脑也没有,只有在网吧混日子)。但是由于回到家中,没有电脑,所以我的文章也只能是断续地写出来,大家请见谅。 最近有朋友问我,哪里可以学好ASP+,我早就说过NGWS中带的文档是最好的...
标签: ASP
  个性化的分页实现 我们前面讲的分页,只不过是通过修改DataGrid的属性来实现分页,这样有这样的好处,最大的就是简单,呵呵,根本不用操心,分页是如何产生的。 但是它同样有缺点,不能按照我们想像的产生各种我们需要的样式。 没有办法,想个性化功能,只有自已动手来做了,呵呵。 我们一步步的来,首先是导入需要的命名空间。下面...

经验教程

630

收藏

86

精华推荐

亲密接触ASP.Net(4)

亲密接触ASP.Net(4)

一剑⑤风云

亲密接触ASP+(1)

亲密接触ASP+(1)

回眸凝笑人以去

亲密接触ASP+(2)

亲密接触ASP+(2)

ffflll60

微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部