views:

1795

answers:

3

Using ASP.Net 2.0

I need an example of how to load a GridView after clicking a button on the page.

I am unable to get the events right - with the PostBack in the PageLoad, seems it's not getting it right. I have three textboxes whose contents are passed to a query which is executed and a datatable is returned. But how and in which order?

Thansk, Bob

+1  A: 

Can you add the code that you are using so we can see what mistakes you may be making. Basically, your steps should look like this:

  1. Add event handler to button to call a method
  2. Within method, retrieve data from database into a datatable
  3. Set the gridview.datasource to the new datatable
  4. run gridview.databind to bind the data to the grid
Justin Balvanz
A: 

Are you looking for an overview of the page event lifecycle? If so, you might check out this MSDN article:

http://msdn.microsoft.com/en-us/library/ms178472.aspx

In summary, the events fire in this order:

  • PreInit
  • Init
  • InitComplete
  • PreLoad
  • Load
  • (Events from your controls, including things like "TextChanged" on a TextBox)
  • LoadComplete
  • PreRender
  • SaveStateComplete
  • Render
  • Unload

Hope that helps!

Brian Sullivan
A: 

Link below will definitely help you in getting what you want

http://csharpdotnetfreak.blogspot.com/2009/04/linkbutton-gridview-querystring.html