protected void ShowGrid() { SqlConnection conn = new SqlConnection(@"data source = localhost; integrated security = true; database = northwind"); SqlCommand cmd = null; SqlDataReader rdr = null; string sqlsel = "SELECT * FROM Magician"; try { conn.Open(); cmd = new SqlCommand(sqlsel, conn); rdr = cmd.ExecuteReader(); HomeGridView.DataSource = rdr; HomeGridView.DataBind(); Message.Text = "Data fetched successfully!"; } catch (Exception err) { Message.Text = err.Message; } finally { conn.Close(); } }
private void RefreshGridView() { HomeGridView.DataSource = GetRandomProducts(); HomeGridView.DataBind(); }