这样来:
if(e.Item.ItemIndex!=-1)
{
  foreach (System.Web.UI.WebControls.Label c in e.Item.Cells[0].Controls)
  {
      if(c.Text == (DataGrid1.CurrentPageIndex + 1).ToString())
          c.ForeColor = Color.Red;
  }
}

解决方案 »

  1.   

    1
    foreach (System.Web.UI.WebControls.Label c in e.Item.Cells[0].Controls) 
    这里就不行,因为并非所有的 control 都是 Label
    2
    if(c.Text == (DataGrid1.CurrentPageIndex + 1).ToString())
     这里也不行,可能在DataGrid中有某 cell里的值 是CurrentPageIndex + 1
      

  2.   

    1
    foreach (System.Web.UI.WebControls.Label c in e.Item.Cells[0].Controls) 
    这里就不行,因为并非所有的 control 都是 Label
    2
    if(c.Text == (DataGrid1.CurrentPageIndex + 1).ToString())
     这里也不行,可能在DataGrid中有某 cell里的值 是CurrentPageIndex + 1
      

  3.   

    把if (e.Item.ItemType == ListItemType.Pager) //这里就不行啊
    {
      foreach (Control c in e.Item.Cells[0].Controls)
      {
        if (c is Label && ((Label)c).Text == (DataGrid1.CurrentPageIndex + 1).ToString()) //这里也不行
        {
          ((Label)c).ForeColor = Color.Red;
        }
      }
    }
    放在ItemCreated里面