Click here to Skip to main content
15,076,991 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
in webform ,while button is clicked want to display a gridview but the main condition is with out page loading event how?

What I have tried:

Here i am using page load,with out page load how to do this?

<pre> protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { 
              
                
            }
           
            }
        
       
    protected void Button1_Click(object sender, EventArgs e)
        {
        
        

                try
                {

                   

                    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();


                }

                catch
                {

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

                }
Posted
Updated 13-Mar-17 22:55pm
Comments
Karthik_Mahalingam 14-Mar-17 1:55am
   
Dont Repost , instead update the existing question using Improve question button
GrpSMK 14-Mar-17 1:57am
   
sorry this is my exact scenario thats y posted
Karthik_Mahalingam 14-Mar-17 4:51am
   
Always use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.
sachin.vishwa90 14-Mar-17 2:40am
   
hi, Page Load event will occur each and every time, whenever postback happens. However you can avoid the entire page load by having Update Panel in your aspx pages.
try to drill down the update panel functionality and use that in your aspx page.
Are you purposely want to avoid the pageload?

http://ajax.net-tutorials.com/controls/updatepanel-control/
GrpSMK 14-Mar-17 3:13am
   
yes its my task,have to bind data with out page load event
F-ES Sitecore 14-Mar-17 5:02am
   
What's wrong with what you've got? Just delete the page_load event and the code runs on the button click.
GrpSMK 14-Mar-17 3:46am
   
can any body give example?

Use GridView inside UpdatePanel and declare the button as a Trigger.
Comments
GrpSMK 14-Mar-17 4:56am
   
can you say some example?
   
You should try yourself. Google "Asp.NET UpdatePanel".
if you dont want to use Page load event, then you will have to go for Ajax
Bind Dataset to ASP.Net GridView using jQuery AJAX[^]
   

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