把默认的select语句放到
if(!Page.IsPostBack)
{
      SqlDataSource1.SelectCommand = "SELECT [TolFloor], [Floor], [Rate], [UserId], [Moddate] FROM [t_floorrate]";  
}
里试试?

解决方案 »

  1.   

    GridView1.DataSourceID = "SqlDataSource1";
    这句为什么不在页面静态编码?
      

  2.   

    注意:在Page_Load里写,不要在Button_Click里写。
    if (TextBox1.Text.Trim().Length > 0)
    {
                int x = Convert.ToInt32(TextBox1.Text);
                SqlDataSource1.SelectParameters.Clear();
                SqlDataSource1.SelectCommand = "SELECT [TolFloor], [Floor], [Rate], [UserId], [Moddate] FROM [t_floorrate] where    TolFloor=" + x;
    }
    else
    {
                SqlDataSource1.SelectCommand = "SELECT [TolFloor], [Floor], [Rate], [UserId], [Moddate] FROM [t_floorrate]";}
    GridView1.DataSourceID = "SqlDataSource1"; 
    //另外,不用再GridView1.DataBind()了!