Click here to Skip to main content
15,887,936 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi..me sakshi.
i am creating a c#.net windows application with vs-2005 and ms sql.

My problem is--

I have a datatable having year,state,district,tehsil etc.

At login page i have to select year,state corrosponding to particular year from combobox.

on form2(where i go after login) there is a combo for district,tehsil.

i want that when i select year,state at login and submit the form then on form2 there should be districts in combo only related to the particular year and state which i have selected at login page.

please help me....

thanks.
Posted
Comments
khandelwal g 29-Jun-10 5:54am    
thanks..
but what abt the query using that we select the state at login and get the district at form2..from where we get the district now??i am confused..

Hi,

there are many ways to do tat and here is one of the way:

* Create 2 properties STATE & YEAR in Form2.cs to set the values in Form1.cs

string stat;
     int yr;
     public string STATE
     {
         get { return stat; }
         set { stat = value; }
     }
     public int YEAR
     {
         get { return yr; }
         set { yr = value; }
     }


* Create an object f2 for Form2 in Form1.cs and set the values of State & Year as after selecting from combobox values:


f2.STATE = cmbstate.SelectedItem.ToString();
     f2.YEAR = int.Parse(cmbyear.SelectedItem.ToString());



* Now u can use these values and can query as per requirements in Form2.cs.
 
Share this answer
 
v2
What you need to do is have the some properties in form2 and populate them on intialise.

So in form1 (Login) you call form2.

Form2 will have code as follows...

C#
public Form2()
       {
           InitializeComponent();
       }


What you need to do is add a property (Or just a variable, depends how many places you want to use the value)

C#
private string selectedYear;
       private string selectedCountry;

       public Form2(string p_selectedYear, string p_selectedCountry)
       {
           selectedYear = p_selectedYear;
           selectedCountry = p_selectedCountry;
           InitializeComponent();
       }


And thats pretty much it.

When you call the Form2 from the Login form....

C#
private void button1_Click(object sender, EventArgs e)
      {
          Form2 newLogin = new Form2("2010", "United Kingdom");
 newLogin.Show();
      }
 
Share this answer
 
Comments
Rob Branaghan 29-Jun-10 7:56am    
Are you wanting the SQL for the Login as well? Is that what you are asking?
you can create a public property in destination page ex:year and state.

Access these properties from the source page and assign then the values. on on form 2 you can use the year and state values.


public int _year;
public int year
{
get
{
return _year;
}


set

{
_year = value;
}
}


similarly do it for state.



in form2 access the year property and assign it the value of the year.
 
Share this answer
 

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