这两天正在学习DataGrid,我的代码,很简单,查了白天资料,搞了半天,那个分页的">"老是点不了: 
ASPX:
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 272px; POSITION: absolute; TOP: 152px"
runat="server" AutoGenerateColumns="False" AllowPaging="True" PageSize="5" AllowCustomPaging="true">
<Columns>
<asp:BoundColumn DataField="ProductID" HeaderText="产品ID"></asp:BoundColumn>
<asp:BoundColumn DataField="ProductName" HeaderText="产品名称"></asp:BoundColumn>
<asp:BoundColumn DataField="QuantityPerUnit" HeaderText="数量"></asp:BoundColumn>
<asp:BoundColumn DataField="UnitPrice" HeaderText="单价"></asp:BoundColumn>
<asp:BoundColumn DataField="UnitsInStock" HeaderText="每股"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
CS:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack){
BindGrid();
}
} private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
//Response.Write("fanle!!!!");
DataGrid1.CurrentPageIndex=e.NewPageIndex;
BindGrid();
} public void BindGrid()
{
SqlConnection  myConnection = new SqlConnection(@"server=(local);database=NorthWind;uid=sa;pwd=;");
myConnection.Open();   
SqlCommand myCommand = new SqlCommand("select * from Products", 
myConnection);
SqlDataAdapter dataAdapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
dataAdapter.Fill(ds); DataGrid1.DataSource=ds;
DataGrid1.DataBind();
myConnection.Close();
}

解决方案 »

  1.   

    1.确认数据库记录多于DataGrid一页记录数
    2.查看翻页事件是否丢失...
      

  2.   

    事件委托丢失了
    this.ListView.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.ListView_PageIndexChanged);
      

  3.   

    记录肯定是多于一页的,我现在数据显示没有问题,就是只能显示第一页的.PageSize设几条就显示几条.很郁闷.事件委托也有:this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
      

  4.   

    搞定了,靠,应该把 AllowCustomPaging="true"去掉