哥哥姐姐们,帮帮忙!!dataGrid分页的时候,怎么知道当前是第几页呀?小女子万分感激!!

birdsmaller 2004-08-11 06:48:33
dataGrid分页的时候,怎么知道当前是第几页呀?在Datagrid中分也按钮隐藏了,通过别的按钮设置分页的,可是这些分页按钮都是在知道当前页是第几页的前提下才能运行的,怎么知道当前是第几页呀?
...全文
223 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
herony420 2004-08-12
  • 打赏
  • 举报
回复
MyDataGrid.CurrentPageIndex = e.NewPageIndex;
如果是自定义的分页,当前页可以通过ViewStat来完成
cjzlxy 2004-08-12
  • 打赏
  • 举报
回复
up
birdsmaller 2004-08-12
  • 打赏
  • 举报
回复
谢谢诸位,我感动一下,呵呵
csq0516 2004-08-11
  • 打赏
  • 举报
回复
up
pll37 2004-08-11
  • 打赏
  • 举报
回复
上面有点错误,
if(e.NewPageIndex <= DataGrid1.PageCount && e.NewPageIndex >=0 )
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
}
else
{
DataGrid1.CurrentPageIndex = 0;
}
BindGrid();
因为索引从0开始
pll37 2004-08-11
  • 打赏
  • 举报
回复
int pageIndex = DataGrid1.CurrentPageIndex; //获得当前页号

如果要改变显示分页,楼上写的很详细了
private void MyDataGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
if(e.NewPageIndex <= DataGrid1.PageCount && e.NewPageIndex >0 )
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
}
else
{
DataGrid1.CurrentPageIndex = 1;
}
BindGrid();
}
realljx 2004-08-11
  • 打赏
  • 举报
回复
好详细啊~
private void MyDataGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
//处理按下数字的方法 最好在这里判断一下
NewPageIndex 是否超出了MyDataGrid的页面范围 因为可能数据在这个过程中已经发生了改变, MyDataGrid.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
zhousinan 2004-08-11
  • 打赏
  • 举报
回复
先定义ASPX页面,注意AllowCustomPaging要设为"False":
<body>
<form id="DictList" method="post" runat="server">
<TABLE style="BORDER-COLLAPSE: collapse" cellSpacing="0" width="100%" border="1">
<TR>
<td bgColor="#c0c000">信息:<FONT face="Arial" color="#ffffff">数据维护</FONT>
</td>
</TR>
<tr>
<td><FONT face="宋体"></FONT></td>
</tr>
<tr>
<td><asp:datagrid id="MyDataGrid" runat="server" Width="100%" PageSize="20" AllowPaging="True" AutoGenerateColumns="False" DataKeyField="FDictid">
<SelectedItemStyle BackColor="#FFC080"></SelectedItemStyle>
<HeaderStyle BackColor="#C0C000"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="选择" HeaderText="选择" CommandName="Select">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" Width="8%"></HeaderStyle>
<ItemStyle Font-Bold="True" HorizontalAlign="Center"></ItemStyle>
</asp:ButtonColumn>
<asp:BoundColumn DataField="FDictID" SortExpression="FDictID asc" HeaderText="标识号">
<HeaderStyle Width="15%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="FNameCn" SortExpression="FNameCn asc" HeaderText="名称">
<HeaderStyle Width="15%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="FNameEn" SortExpression="FNameEn asc" HeaderText="英文名称">
<HeaderStyle Width="15%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="FNote" SortExpression="FNote asc" HeaderText="描叙">
<HeaderStyle Width="47%"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle Visible="False"></PagerStyle>
</asp:datagrid></td>
</tr>
</TABLE>
<TABLE style="BORDER-COLLAPSE: collapse" cellSpacing="0" width="100%" bgColor="#ff9966" border="1">
<TR>
<td align="right"><asp:linkbutton id="btnFirst" runat="server" CommandArgument="fist">首页</asp:linkbutton>  
<asp:linkbutton id="btnPrev" runat="server" Width="36px" CommandArgument="prev">上一页</asp:linkbutton>  
<asp:linkbutton id="btnNext" runat="server" CommandArgument="next">下一页</asp:linkbutton>  
<asp:linkbutton id="btnLast" runat="server" CommandArgument="last">末页</asp:linkbutton>  
<asp:label id="lblCurrentIndex" runat="server"></asp:label>/<asp:label id="lblPageCount" runat="server"></asp:label>  
跳转到<asp:TextBox id="txtGoPage" runat="server" Width="30px" CssClass="textbox"></asp:TextBox>
<asp:Button id="btnGo" runat="server" Text="GO" CssClass="button" Width="29px"></asp:Button></td>
</TR>
</TABLE>
</form>







codebehind主要功能部分代码:



private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
myConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnString"]);

if (!IsPostBack)
BindGrid();
}



public void BindGrid()
{
string strSql ="SELECT * FROM t_dict ";
SqlDataAdapter myCommand = new SqlDataAdapter(strSql, myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "t_dict");
MyDataGrid.DataSource=ds.Tables["t_dict"].DefaultView;
MyDataGrid.DataBind();
ShowStatsPage();
}

private void PagerButtonClick(object sender, System.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 ("fist"):
MyDataGrid.CurrentPageIndex=0;
break;
case ("last"):
MyDataGrid.CurrentPageIndex = (MyDataGrid.PageCount - 1);
break;
default:
//本页值
MyDataGrid.CurrentPageIndex = Convert.ToInt32(arg);
break;
}
BindGrid();
}

void ShowStatsPage()
{
//显示页面信息
lblCurrentIndex.Text = "[<font color="blue">当前为第:" + ((int)MyDataGrid.CurrentPageIndex+1) + "页</font>]";
lblPageCount.Text = "[<font color="blue">共:" + MyDataGrid.PageCount + "页</font>]";
}



private void MyDataGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
//处理按下数字的方法
MyDataGrid.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}



private void btnGo_Click(object sender, System.EventArgs e)
{
//页面直接跳转的代码
if(txtGoPage.Text.Trim()!="")
{
int PageI=Int32.Parse(txtGoPage.Text.Trim())-1;
if (PageI >=0 && PageI < (MyDataGrid.PageCount))
MyDataGrid.CurrentPageIndex = PageI ;
}
BindGrid();
}
//----------------------翻页代码结束
triout 2004-08-11
  • 打赏
  • 举报
回复
另外,分页按钮的事件中有CurrentPageIndex属性的。
triout 2004-08-11
  • 打赏
  • 举报
回复
CurrentPageIndex
分页的英文是pagination,记住这个单词,因为会经常遇见。在EasyUI框架下,datagrid使用分页简单到令人发指,只需要2点:1,为table启用class=”easyui-datagrid”,这样table就成为了一个数据网格。2,为table启用pagination=”true”,表示表格启用分页功能。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧