Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to display grid view only when button is clicked,if i refresh the page should not display the grid view display only button...how to do this?

What I have tried:

C#
<pre>        protected void Page_Load(object sender, EventArgs e)
        {
          
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {

                SqlConnection con = new SqlConnection(@"user id=sa;password=ssa;database=Mohan;data source=PCTH101\PCTH101");

                con.Open();

                SqlCommand cmd = new SqlCommand("select * from bind", con);

                cmd.CommandType = CommandType.Text;

                SqlDataAdapter da = new SqlDataAdapter(cmd);

                DataSet ds = new DataSet();

                da.Fill(ds, "bind");

                GridView1.DataSource = ds.Tables["bind"]; ;

                GridView1.DataBind();
                this.GridView1.Visible = true;

            }

            catch
            {

                Response.Write("<script>alert('No record Found')</script>");

            }
        }
    }
Posted
Updated 12-Mar-17 23:50pm
Comments
Ayodeji Oluwatomiwo 13-Mar-17 5:55am    
Simply create a function that will fetch the data from whatever source that you're using.
Then add the function to the click event of the button

OR

Also, on your page load, set the Grid visibility to hidden

protected void Page_Load(object sender, EventArgs e)
        {
          GridView1.Visible = false;
        } 
GrpSMK 13-Mar-17 6:05am    
it doesnt show grid view never
Karthik_Mahalingam 14-Mar-17 1:54am    
Always use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900