日期:2014-05-19  浏览次数:20402 次

DataGrid 分页(.NET2003)
<asp:DataGrid   AllowPaging= "true "   BorderColor= "#999999 "   BorderWidth= "1 "   CellPadding= "5 "   CellSpacing= "0 "   CssClass= "STYLE3 "   ID= "dgrdMain "   runat= "server ">
<PagerStyle       NextPageText= "下一页 "   PrevPageText= "上一页 "> </PagerStyle>
</asp:DataGrid>

其他代码完全正确.只是设置分页出错.
点上一页下一页.都没反映.晕死.
这里没有.NET的工具来进行属性设置.
只有自己写.代码改.
代码为.NET2003的.

------解决方案--------------------
控件应该加上: OnPageIndexChanged= "MyDataGrid_Page "
比如:
<asp:datagrid id= "MyDataGrid " runat= "server " AutoGenerateColumns= "False "
HorizontalAlign= "Center " AlternatingItemStyle-BackColor= "#eeeeee "
HeaderStyle-BackColor= "#aaaadd " Font-Size= "8pt " Font-Name= "Verdana "
CellSpacing= "0 " CellPadding= "3 " GridLines= "Both " BorderWidth= "1 "
BorderColor= "black " OnPageIndexChanged= "MyDataGrid_Page " PagerStyle-HorizontalAlign= "Right "
PagerStyle-Mode= "NumericPages " PageSize= "5 " AllowPaging= "True ">
cs:
public void MyDataGrid_Page(object sender, DataGridPageChangedEventArgs e)
{
//int startIndex ;
//startIndex = MyDataGrid.CurrentPageIndex * MyDataGrid.PageSize;
MyDataGrid.CurrentPageIndex = e.NewPageIndex;
BindGrid();
ShowStats();
}

------解决方案--------------------
没有设置PageIndexChanged事件
应该是这样
private void DataGrid1_PageIndexChanged_1(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex=e.NewPageIndex;//实现分页
this.DataGrid1.DataBind();
//分页事件了数据要重新绑定下
}