Since your method return type is void you can't check for null.
So to check the method you need to change the return type.
Check the below example.
public string refreshdata()
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand("select * from tbl_data", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
return "1";
}
else
{
return "";
}
}
Then you can check the null using below code.
if (!string.IsNullOrEmpty(refreshdata()))
{
}