在index.aspx里:
DataGrid1.CurrentPageIndex = (int)Request["page"];
DataGrid1.DataSource = ...;
DataGrid1.DataBind();
DataGrid1.CurrentPageIndex = (int)Request["page"];
DataGrid1.DataSource = ...;
DataGrid1.DataBind();
解决方案 »
- 基础问题 不懂
- 艰难问题 考虑很久还不会大虾们来看看 帮个忙很着急
- 孟子,为什么我这里不能冻结某列呢...
- 用户控件中图片引用的问题,希望大家都来谈谈自己的实现方法,希望大家探讨自己在项目中是怎么运用的,有没有方法可以解决下面的情况的缺
- 这里少WIKI的文章呀?有讨论的吗?
- 存储过程
- datagrid的问题,希望能够获得点击记录的ID值
- 哪有语音聊天的原理介绍或者提供语音聊天软件源代码下载的地方?谢谢
- SqlBulkCopy 从数据库中一个表添加到另一个表。列数不同的时候
- 如何将导出的Excel中的列设置指定的宽度???
- 帮忙!!!
- 网页里嵌入ActiveX后JavaScript怎么样响应ActiveX里的事件!
{
if ( ! this.IsPostBack )
{
SetModel();
this.Bind();
}
} private void SetModel()
{
cPage="1";
if(Request.Params["Page"]!=null)
{
cPage=Request.Params["Page"];
DataGrid1.CurrentPageIndex=int.Parse(cPage)-1;
}
}
private void Bind()
{
...... this.DataGrid1.DataSource = ds.Tables[0].DefaultView;
this.DataGrid1.DataBind();
Pagination();
}
private void Pagination()
{
PageInfo.Text="页次:"+(DataGrid1.CurrentPageIndex+1)+"/"+DataGrid1.PageCount+" 每页"+DataGrid1.PageSize+"个主题 ";
JumpTo.Text="" + (DataGrid1.CurrentPageIndex+1); if (DataGrid1.CurrentPageIndex == 0)
{
PageLink.Text="[首页] [上一页] ";
}
else
{
PageLink.Text="[<a href='Pubdoclist.aspx?id=0&Page=1'>首页</a>] [<a href='Pubdoclist.aspx?id=0&Page="+(DataGrid1.CurrentPageIndex)+"'>上一页</a>] ";
}
if (DataGrid1.CurrentPageIndex == DataGrid1.PageCount-1)
{ PageLink.Text=PageLink.Text+"[下一页] [尾页] ";
}
else
{
PageLink.Text=PageLink.Text+"[<a href='Pubdoclist.aspx?id=0&Page="+(DataGrid1.CurrentPageIndex+2)+"'>下一页</a>] [<a href='Pubdoclist.aspx?id=0&Page="+DataGrid1.PageCount+"'>尾页</a>] ";
}
}
private void Page_Load(object sender, System.EventArgs e)
{
string Name = Request.QueryString["Name"];
//Name = Server.UrlEncode(Name);
Name = Server.HtmlEncode (Name);
//创建连接字符串
string strConnection = "user id=sa;password=sqlgoodboy;";
strConnection += "initial catalog=PrimordialMusic;data source=127.0.0.1;";
strConnection += "Connect Timeout=30";
//创建查询字符串
string strSQL = "SELECT * FROM \"Music\" where title like '%" + Name + "%'";
//string strSQL = "select * from singers join songs on singers.singer_id=songs.singer_id join album on songs.album_id=album.album_id where song_name like '%张%' or album_name like '%张%' or singer_name like '%张%'";
SqlConnection objConnection = new SqlConnection(strConnection);
SqlDataAdapter objAdapter = new SqlDataAdapter(strSQL,objConnection);
DataSet objDataSet = new DataSet();
objAdapter.Fill(objDataSet,"singers");
DataView objDataView = new DataView(objDataSet.Tables["singers"]);
dgNameList.DataSource = objDataView;
dgNameList.DataBind();
}
其实datgrid本身的分页是非常简单的,但也扩展性比较差,有时还会出错,推荐使用你这种或http://www.csdn.net/Develop/Read_Article.asp?Id=16055里面的分页控件。
PageInfo:是页信息,如PageInfo.Text="页次:"+(dgfblist.CurrentPageIndex+1)+"/"+dgfblist.PageCount+" 每页"+dgfblist.PageSize+"个主题 ";
JumpTo:是一个textbox,用于输入跳转的页次。
PageLink:是一个label,如PageLink.Text="[首页] [上一页] ";PageLink.Text=PageLink.Text+"[下一页] [尾页] ";
ms-help://MS.VSCC/MS.MSDNVS.2052/Vbcon/html/vbwlkWalkthroughDisplayingDataInListBoxesOnWebFormsPage.htm