load dataset once use dataview throughout page asp.net c#

i've been using asp for years now and dont have much experience with OOP.  i have a simple question that i cant find the answer to.
How can i load a dataset(2 datatables) on the Page_load() once and the use those tables on different events.

i have a ddl and a gridview.  on the page_load i want to load and populate the dataset - know how to do this
i have a button next to the ddl  user selects ddl value and hits button - know how to do this
onclick event of the button is onclick="button_click"
is there a way that i dont have t requery the DB and just use the datatable that i loaded

 //connect and fill dataset
//bind the ddl
ddl_yards.DataSource = ds.Tables["Yards"];

ds.Tables["Equip"] // datatable just made and not used yet - make this public so that the other functions can see it.  how???????


void button_click(Object Sender, EventArgs e)
  // i dont want to reconnect to the db to access the equip table every time the user click this button.
  // how can i access the "equip" datatable from inside of here that was made on the Page_load()?  so that i can bind it to a gridview - dont know how to do????????
 // do i make the dataset public? private?
 GridView1.DataSource = ds.Tables["Equip"];


Who is Participating?
I wear a lot of hats...


just declare your dataset as public outside the Page_load event
public static DataSet ds=null;
keep in mind asp.net is stateless.  if you dont want to requery you need to use some sort of sessionstate.
OWASP Proactive Controls


Experts Exchange Solution brought to you by

Your issues matter to us.


Start your 7-day free trial
cay187Author Commented:
so if i load the dataset to the client the first time i need to cache it in order to reuse it again?  or save that dataset into session variables to reuse it on later events?
yes when you load it for the first time you can store it using session variable.  just be careful with hundreds/thousands of users this will eat server resources.

From novice to tech pro — start learning today.