I have called a Code behind method using jQuery using Static web Method. That web method call was success but when i bind grid view inside that method , gives an error that, we can not use control in static method.how can we solve this problem ?.
public static DataTable GetDataTable()
{
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand("StoredProcedurename");
String constr = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
string Startdate = DateTime.Now.ToString("yyyy-MM-dd");
string EndDate = Convert.ToDateTime(Startdate).AddMonths(-6).ToString("yyyy-MM-dd");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@FromDate", Startdate);
cmd.Parameters.AddWithValue("@ToDate", EndDate );
cmd.Connection = con;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds);
//i want to use same dataset to bind with the grid
gridToBind.DataSource = ds.Tables[1];
gridToBind.DataBind();
txtStatus.Text="Data Received";
//above three lines throws error.
return ds.Tables[1];
}
And getting error " An object reference is required for the non-static field, method, or property "