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

ASP:DataGrid不能分页,大家帮忙看看
<%@   Page   Language= "C# "   Debug= "true "   %>
<%@   Import   Namespace= "System.Data "   %>
<%@   Import   Namespace= "System.Web.Security   "   %>
<%@   Import   Namespace= "System.Data.OleDb "   %>  

<script   language= "C# "   runat=server>
    void   Page_Load()
    {
        string   strConnection   =   "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA   SOURCE= "   +   Server.MapPath( "local.mdb ")   +   "; ";
        string   strSQL   =   "SELECT   *   FROM   MOBILE_CALL_TICKET_ZRY ";
        DataSet   objDataSet   =   new   DataSet();
        OleDbConnection   objConnection   =   new   OleDbConnection(strConnection);
        OleDbDataAdapter   objAdapter   =   new   OleDbDataAdapter(strSQL,   objConnection);
        objAdapter.Fill(objDataSet,   "Employees ");
        DataView   objDataView   =   new   DataView(objDataSet.Tables[ "Employees "]);
        dgNameList.DataSource=objDataView;
        dgNameList.DataBind();
//Console.WriteLine(buffer);
}
</script>
<ASP:DataGrid   id= "dgNameList "   runat= "server "
style= "LEFT:   100px;   POSITION:   absolute;   TOP:   300px; "
AllowPaging= "True "
PageSize= "2 "
PagerStyle-HorizontalAlign= "Right "
BorderColor= "black "
BorderWidth= "1 "
GridLines= "Both "
CellPadding= "3 "
CellSpacing= "0 "
Font-Name= "Verdana "
Font-Size= "8pt "
HeaderStyle-BackColor= "#aaaadd "
AlternatingItemStyle-BackColor= "#aaaadd "
PagerStyle-NextPageText= "下一页 "
PagerStyle-PrevPageText= "上一页 "
/>
无报错,能显示出表格,但是单击“下一页”无反应。请大家帮帮忙

------解决方案--------------------
记得在this.dgNameList.CurrentPageIndex = e.NewPageIndex;后面加上
BindGrid();

重新绑定一下数据如

void BindGrid()
{
string strConnection = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE= " + Server.MapPath( "local.mdb ") + "; ";
string strSQL = "SELECT * FROM MOBILE_CALL_TICKET_ZRY ";
DataSet objDataSet = new DataSet();
OleDbConnection objConnection = new OleDbConnection(strConnection);
OleDbDataAdapter objAdapter = new OleDbDataAdapter(strSQL, objConnection);
objAdapter.Fill(objDataSet, "Employees ");
DataView objDataView = new DataView(objDataSet.Tables[ "Employees "]);
dgNameList.DataSource=objDataView;
dgNameList.DataBind();
}

------解决方案--------------------
在PageIndexChanged里改变当前页:

dgNameList.CurrentPageIndex = e.NewPageIndex;
......然后,重新绑定
------解决方案--------------------
<%@ Page Language= "C# " Debug= "true " %>
<%@ Import Namespace= "System.Data " %>
<%@ Import Namespace= "System.W