void BindGrid()
{
EventLog aLog=new EventLog();
aLog.Log="Application";
aLog.MachineName=".";LogGrid.DataSource=aLog.Entries;
LogGrid.DataBind();
}

解决方案 »

  1.   

    UPvoid BindGrid()
    {
    EventLog aLog=new EventLog();
    aLog.Log="Application";
    aLog.MachineName=".";//现在这,比如对Index排序,如何写,或给个思路。谢了LogGrid.DataSource=aLog.Entries;
    LogGrid.DataBind();
    }
      

  2.   

    write a custom IComparer, seehttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsicomparerclasscomparetopic.asp(didn't test, so there might be errors):public class YourCustomComparer : IComparer
    {
      public int Compare(object x,object y)
      {
    EventLogEntry a = (EventLogEntry)x;
    EventLogEntry b = (EventLogEntry)y; return a.Index - b.Index;
      }
    }EventLogEntryCollection ec = aLog.Entries;
    EventLogEntry[] ees = new EventLogEntry[ec.Count];
    ec.CopyTo(ees,0);Array.Sort(ees, new YourCustomComparer());LogGrid.DataSource = ees;