By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,991 Members | 1,888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,991 IT Pros & Developers. It's quick & easy.

Create a global-acting DataSet

100+
P: 132
Hi there.

Is there a way to create a DataSet within one Button click event that can then be used in a foreach command in another Button click event, please?

Thank you.

M :)
Jan 14 '09 #1
Share this Question
Share on Google+
5 Replies


Plater
Expert 5K+
P: 7,872
Have the dataset be available to the class(Page) and manipulate it from your button functions.

introduction to oop - Google Search
Jan 14 '09 #2

100+
P: 132
@Plater
Hi there.

I have declared the DatSet at the head of the code, outside any method so hence I thought this would give scope of the DataSet to any method within the class..?

Sorry if this sounds daft but what do I need to do otherwise to make the DataSet available to all methods in the class, please?

I should add that the current class has a button click event and it is within here that the DataSet is being returned from a web service. This button click method has several if-conditions over whioch web service method is called, so hence there was one of multiple possible DataSets returned.

Hope that makes some sense..?

Thank you.

M :)
Jan 15 '09 #3

vekipeki
Expert 100+
P: 229
It is still not very clear what is the problem.

Any class member, private/public/protected, is always visible to other members of that class:

Expand|Select|Wrap|Line Numbers
  1. class MyClass
  2. {
  3.       private DataSet _dataSet;
  4.       private void DoSomething()
  5.       {
  6.               // if it is a member of this class,
  7.               // we can access it.
  8.               _dataSet = new DataSet();
  9.       }
  10. }
  11.  
Why do you think you cannot access your DataSet from class' methods?
Jan 15 '09 #4

Plater
Expert 5K+
P: 7,872
To expand for your situation:

Expand|Select|Wrap|Line Numbers
  1. class MyClass 
  2.       private DataSet _dataSet =null; 
  3.       private void FirstButtonClick() 
  4.       { 
  5.           _dataSet=SomePopulateMethod();
  6.       } 
  7.       private void SecondButtonClick() 
  8.       { 
  9.           if(_dataSet!=null)
  10.           {//first button was clicked
  11.               //do something with _dataSet
  12.           }
  13.       }      
  14.  
You should know that button clicks on webpages also call the Page_Load() function again, which could be what is causing your confusion.
Jan 15 '09 #5

100+
P: 132
Hi there.

the final solution to my "global" DataSet was simply to use a Session Variable and store the current returned DataSet ( within the Button click event) in there; job done.

Thank you.

M :)
Jan 19 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.