首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

DataGrid 分页(.NET2003),该怎么解决

2012-01-26 
DataGrid 分页(.NET2003)asp:DataGridAllowPaging true BorderColor #999999 BorderWidth 1 Cel

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();
//分页事件了数据要重新绑定下
}

热点排行