先用DataView取数据,然后再重新绑定你的DataGrid

解决方案 »

  1.   

    好像 是 dataGrid1.CurrentSelectIndex我不记得了,只要打出c就可以了,它就出来了
      

  2.   

    当前的cell的数据或是记录?
      

  3.   

    .cs下:
    public DataSet staff(string xueli)  
    {SqlDataAdapter MyAdapter= new SqlDataAdapter();// Create Instance of Connection and Command Object
    SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["test"]);
    MyAdapter.SelectCommand  = new SqlCommand("p_staff", myConnection);// Mark the Command as a SPROC
    MyAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;SqlParameter parameterxueli = new SqlParameter("@xueli", SqlDbType.VarChar, 6);
    parameterxueli.Value =xueli;
    MyAdapter.SelectCommand.Parameters.Add(parameterxueli);
    // Open the database connection and execute the command
    DataSet ds=new DataSet();

    myConnection.Open();
    try
    {
      MyAdapter.Fill(ds);
      return ds;
    }
    finally
    {
       myConnection.Close();
    }
    }//endaspx下:
    public void  BindGrid(string sortfield)
     {
        LOVECsharp.p_staff myErp=new LOVECsharp.p_staff();
        DataSet ds=myErp.staff(Ddl1.SelectedItem.Text.ToString());
        DataView source = ds.Tables[0].DefaultView;
        source.Sort=sortfield;
        DataGrid1.DataSource=source;
        DataGrid1.DataBind();
     }
    private void Btn_check_Click(object sender, System.EventArgs e)
    {
      DataGrid1.CurrentPageIndex=0;
      BindGrid("工资");
     }