|
-
Feb 2nd, 2007, 06:52 PM
#1
Thread Starter
Addicted Member
Passing a value of a variable from the main page to a custom class
i am trying to pass a value from my main page to a customm class
i've read and read and read but nothing is sinking in
ok on the main webpage there is a dropdown list i want the selected index (int) to be passed to my custom class so it may determine which dataset to pass back to the main page.
any help is appreciated
Visual C# 2003
Last edited by KingSatan; Feb 2nd, 2007 at 07:09 PM.
-
Feb 4th, 2007, 09:49 AM
#2
Hyperactive Member
Re: Passing a value of a variable from the main page to a custom class
Main class:
contains variable : int x.
classOb a = new classOb(this);
Object class: classOb.cs
private Main m;
// constructor
public classOb(Main v)
{
m=v;
}
m.x // to use the variable x.
I don't know if I misunderstood your question but if you're trying to access a variable from another form, well that's how i do it.
Jennifer
-
Feb 5th, 2007, 12:00 PM
#3
Thread Starter
Addicted Member
Re: Passing a value of a variable from the main page to a custom class
yes i am trying to access varibles from different forms and classes
creating custom classes so all my code isnt on the main forms
thanx
-
Feb 5th, 2007, 06:34 PM
#4
Thread Starter
Addicted Member
Re: Passing a value of a variable from the main page to a custom class
ok im not sure i got it still.... im rusty frm not doing ANYTHING in a long time
i have this as my class im trying to use the index of a dropdownlist as the int which determines which data to pull up
Code:
using System;
namespace TCM
{
public class PInterface
{
public PInterface(Public_Page pp, int a, string m, int sr)
{
if(a.Equals(1))
{
m="1";
}
else
if(a.Equals(2))
{
m="2";
}
else
if(a.Equals(3))
{
m="3";
}
else
if(a.Equals(4))
{
m="4";
}
}
}
}
i guess i dont know how to make the variable visible to my other class(es) and vice versa
Last edited by KingSatan; Feb 7th, 2007 at 12:04 PM.
Reason: miss3ed something
-
Feb 5th, 2007, 09:57 PM
#5
Fanatic Member
Re: Passing a value of a variable from the main page to a custom class
And wheres variable m came from?
-
Feb 7th, 2007, 12:03 PM
#6
Thread Starter
Addicted Member
Re: Passing a value of a variable from the main page to a custom class
sorry "L" was supposed to be changed to "m"
-
Feb 8th, 2007, 07:55 AM
#7
Hyperactive Member
Re: Passing a value of a variable from the main page to a custom class
I dont know if this is what you want, but do you want other classes to access the variable a or m?
Code:
using System;
namespace TCM
{
public class PInterface
{
int a; string m; int str;
public PInterface(int a, string m, int sr)
{
if(a == 1))
{
m="1";
}
else
if(a.Equals(2))
{
m="2";
}
else
if(a.Equals(3))
{
m="3";
}
else
if(a.Equals(4))
{
m="4";
}
}
public int GetM() { return(a); } // method to get a
}
}
// other class
PInterface p = new PInterface();
// to access the variable a:
int x = p.GetM();
I prefer to use the set / get methods rather than the short hand that c# offers, but you could use them if you like.
I don't know if I misunderstood you post. Is this what you want?
Jennifer
-
Feb 8th, 2007, 11:54 AM
#8
Thread Starter
Addicted Member
Re: Passing a value of a variable from the main page to a custom class
no i want the PInterface to get a from the Main page
i want a the main page to get m from Pinterface
side question
would it be the same if m was a dataset?
-
Feb 8th, 2007, 03:03 PM
#9
Hyperactive Member
Re: Passing a value of a variable from the main page to a custom class
public class PInterface
{
public PInterface(frmMain m)
{
this.m = m;
}
m.var // you access the variable var from object m with the dot operator
}
in the frmMain form:
public int var; // you must declare this variable as public or else PInterface will not be able to access it.
var = 9;
Hope this helps,
Jennifer.
-
Feb 20th, 2007, 02:43 PM
#10
Thread Starter
Addicted Member
Re: Passing a value of a variable from the main page to a custom class
what about a dataset?
say i wanted to populate a dropdown box
how would i pass the information from the ds in the custom class to a ds in the main class?
or could i access it like any other public variable?
could you give me an example?
-
Feb 21st, 2007, 02:22 PM
#11
Thread Starter
Addicted Member
Re: Passing a value of a variable from the main page to a custom class
ok sorry folks
keep overlooking my dropdown list data text field
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|