private void Page_Load(object sender, System.EventArgs e)
  {
   if(!IsPostBack)
   {  
    //设置排序表达式
     VeiwState["SortOrder"]="LastName";
    //设置排序的升顺序
    VeiwState["OrderDire"]="ASC";
                 Repeater1_Bind2();
   }
  
   // 在此处放置用户代码以初始化页面
  }
  
  public void chage(object sender,DataGridPageChangedEventArgs e)
  {
   
   
    startIndex = e.NewPageIndex*DataGrid1.PageSize;
   DataGrid1.CurrentPageIndex=e.NewPageIndex;
    
   Repeater1_Bind2();
  
  }
  
  
  private void Repeater1_Bind2()
  {
   
   String Connstr, SQL;
  
   Connstr="server=localhost;database=netService;uid=netService;pwd=netService";
   SQL="Select * from guestbook where isNULL(huida,'')<>'' Order By post_time DESC";
   SqlConnection conn = new SqlConnection(Connstr);
   SqlDataAdapter Cmd=new SqlDataAdapter(SQL,conn);
   DataSet ds=new DataSet();
   try
   {
    Cmd.Fill(ds,"guestbook");
    DataGrid1.DataSource=ds.Tables["guestbook"].DefaultView;
    //设置排序关键字
    string sort=(string)VeiwState["SortOrder"]+""+(string)VeiwState["OrderDire"];
    //设置排序表达式
    view.Sort=sort;
    DataGrid1.DataBind();
   }
   catch(Exception error)
   {
   this.Response.Write(error.ToString());
   }
 
     
  }
  private void DataGrid1_SortCommand(object source , System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
  {
   //取的排序表达式
  string vortExp=e.SortExpression;
          //如果是当前排序表达式
   if(VeiwState["SortOrder"].ToString()==vortExp)
   {
    //如果原来是降序那就该为升序
    if((string)VeiwState["OrderDire"]=="Desc")
     (string)VeiwState["OrderDire"]="ASC";
    else
     (string)VeiwState["OrderDire"]="Desc";
   }
   else
   {
   
   VeiwState["SortOrder"]=e.SortExpression;
   }
   Repeater1_Bind2();
  }