Follow below simple steps:
SqLConnection con=new SqlConnection(ConfigurationManager.ConnectedStrings["NameOfYourConnectionString"].ToString());
- Now goto the click event of button and code as below:
con.open();
SqlCommand cmd=new SqlCommand("select * from YourTableName",con);
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
SqlDataAdapter da=new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
da.Fill(ds);
GridView.DataSource=ds;
GridView.DataBind();
con.close();
}
else
{
}