protected void Page_Load(object sender, EventArgs e) { string queryString = "Select * from Recipes where Isprivate = 0 "; if (!IsPostBack) { if (Session["Username"] != null) { queryString += "or SubmittedBy = " + "'" + Session["Username"] + "' "; } SqlCommand cmd = new SqlCommand(queryString, connect); connect.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { RecipesList.Visible = true; DataResult.DataSource = reader; DataResult.DataBind(); reader.Close(); connect.Close(); } else { NoRecipeAlert.Visible = true; RecipesList.Visible = false; reader.Close(); connect.Close(); } } }