Connecting Tech Pros Worldwide Help | Site Map

Initiallizing problem in Web application

Newbie
 
Join Date: Sep 2009
Posts: 2
#1: Sep 15 '09
hello guys, i hope any one will help in this

i am designing a web application, the page i am workin on its the default.aspx
it contains dropdownboxes

the first 4 to choose the type and the second for to choose the value of the type

when you choose a type a dropdownlist will be filled of values that related of that type.
and when you choose a second type , it will also will filled the value that related of the second type, and it will use the filter of the first dropdownlists to reduce the data. and so on fot the forth type dropdownlist.

i have 3 classes, controller, database, and TypeValue.

when u choose a type, it will send the controller and the controller will create an object of type TypeValue and insert it in array of the same type that has been initialized in the controller.
then it will call the database class to retrieve the values of that type, and it will return the values as an OLEDatareader to the controller then to the Default.aspx to the dropbox of the value.

then when u choose from that list a value, it will call the controller, then the controller will just modify the value parameter in the array in the controller class.

now when the user will select the second value, it will go to the controller and create another object and it will insert it in the second index of the array, the problem that i am facing, is the first index turns to null.

i think this is because the web application will initialize the variables everytime it will call a method in the class. so i want it just to be intiallized once when i call it for the first time. i tried to use the HTTPApllication, method Application_start, this method will be called just one time, which is when the application started, but my problem with this method, is that i cant use the array out side it, if i initiallized the array inside it.

here are the code.


Dropbox to choose the first type
Expand|Select|Wrap|Line Numbers
  1. protected void DropDownList6_SelectedIndexChanged(object sender, EventArgs e) 
  2.                 DropDownList1.Enabled = true;
  3.                 CheckBox5.Enabled = true;
  4.                 oldr = fc.SelectFilterType(DropDownList6.SelectedItem.Value, 0, null );
  5.                 DropDownList1.DataSource = oldr[0];
  6.                 DropDownList1.DataValueField = DropDownList6.SelectedItem.Value;
  7.                 DropDownList1.DataBind();
  8.  
  9. dropbox to choose the second type
  10.     protected void DropDownList7_SelectedIndexChanged(object sender, EventArgs e) 
  11.                 DropDownList2.Enabled = true;
  12.                 CheckBox6.Enabled = true;
  13. null);
  14.                 oldr = fc.SelectFilterType(DropDownList7.SelectedItem.Value, 1, null);
  15.                 DropDownList2.DataSource = oldr[1];
  16.                 DropDownList2.DataValueField = DropDownList7.SelectedItem.Value;
  17.                 DropDownList2.DataBind();
  18.  
  19. dropbox to choose the first value
  20.     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)//first ddl 
  21.     {
  22.         if (DropDownList2.Enabled == true || CheckBox6.Checked == true)
  23.         {
  24.             oldr = fc.SelectFilterValue(DropDownList1.SelectedValue, 0);
  25.             DropDownList2.DataSource = oldr[1];
  26.         }
  27.     }
the controller class
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Data;
  6. using System.Data.OleDb;
  7.  
  8. /// <summary>
  9. /// Summary description for Controller
  10. /// </summary>
  11. public class FilterController 
  12. {
  13.     public string filterType;
  14.     public int listIndex;
  15.     public string filterValue;
  16.  
  17.     public FilterTypeValue[] filterTypeList = new FilterTypeValue[4];
  18.     public DatabaseClass dbClass;
  19.  
  20.  
  21.  
  22.     public FilterController()
  23.     {
  24.  
  25.     }
  26.     public FilterController(string filterType, int listIndex, string filterValue)
  27.     {
  28.         //
  29.         // TODO: Add constructor logic here
  30.         //
  31.         this.filterType = filterType;
  32.         this.filterValue = filterValue;
  33.         this.listIndex = listIndex;
  34.         //filterTypeList[listIndex] = new FilterTypeValue(filterType, filterValue);
  35.  
  36.     }
  37.  
  38.     public OleDbDataReader[] SelectFilterType(string filterType, int listIndex, string filterValue)
  39.     {
  40.         filterTypeList[listIndex] = new FilterTypeValue(filterType, filterValue);
  41.         dbClass = new DatabaseClass(filterTypeList,listIndex);
  42.         return dbClass.FilterData();
  43.     }
  44.     public OleDbDataReader[] SelectFilterValue(string filterValue, int listIndex)
  45.     {
  46.         filterTypeList[listIndex].Value = filterValue;
  47.         if(this.listIndex < 3)
  48.             dbClass = new DatabaseClass((FilterTypeValue[])filterTypeList.Clone(), listIndex + 1);
  49.         return dbClass.FilterData();
  50.     }
TypeValueClass
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5.  
  6. /// <summary>
  7. /// Summary description for Class1
  8. /// </summary>
  9. public class FilterTypeValue
  10. {
  11.     public string filterType;
  12.     public string filterValue;
  13.     public object Clone()
  14.     {
  15.         FilterTypeValue p = new FilterTypeValue(filterType,filterValue);
  16.         return p;
  17.     }
  18.  
  19.  
  20.     public FilterTypeValue(string filterType, string filterValue)
  21.     {
  22.         //
  23.         // TODO: Add constructor logic here
  24.         //
  25.         this.filterType = filterType;
  26.         this.filterValue = filterValue;
  27.     }
  28.     public string FType
  29.     {
  30.         get
  31.         {
  32.             return filterType;
  33.         }
  34.         set
  35.         {
  36.             filterType = value;
  37.         }
  38.     }
  39.     public string Value
  40.     {
  41.         get
  42.         {
  43.             return filterValue;
  44.         }
  45.         set
  46.         {
  47.             filterValue = value;
  48.         }
  49.     }
  50. }
the database class
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Data.OleDb;
  6.  
  7.  
  8.  
  9. /// <summary>
  10. /// Summary description for DatabaseClass
  11. /// </summary>
  12. public class DatabaseClass :HttpApplication
  13. {
  14.     public int connectionNumber;
  15.  
  16.     public OleDbConnection oLDConnection;
  17.     public String connectionString1 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Users\\tabbaanm\\Desktop\\Facility Ins WebAppl\\App_Data\\KPGDatabase.accdb;Persist Security Info=True";
  18.     public OleDbCommand cmd;
  19.     public OleDbDataReader [] oldr = new OleDbDataReader[4];
  20.  
  21.     public string[] t = new string[5];
  22.     public string[] f = new string[4];
  23.  
  24.     FilterTypeValue[] filterTypeList = new FilterTypeValue[4];
  25.  
  26.  
  27.     public DatabaseClass(FilterTypeValue[] filterTypeList, int connectionNumber)
  28.     {
  29.         //
  30.         // TODO: Add constructor logic here
  31.         //
  32.  
  33.         this.connectionNumber = connectionNumber;
  34.         this.filterTypeList = filterTypeList;
  35.     }
  36.     public OleDbDataReader[] FilterData()
  37.     {
  38.         switch (connectionNumber)
  39.         {
  40.             case 0: Connection1();
  41.                 break;
  42.             case 1: Connection2();
  43.                 break;
  44.             case 2: Connection3();
  45.                 break;
  46.             case 3: Connection4();
  47.                 break;
  48.             default: Connection1();
  49.                 break;
  50.         }
  51.         return oldr;
  52.     }
  53.  
Newbie
 
Join Date: Sep 2009
Posts: 2
#2: Sep 15 '09

re: Initiallizing problem in Web application


loool i have solved it,, i made the array as static to be initiazlied once, and now its working

if i have any problems in coding, i think i will be post here :D
Reply