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_sta rt, 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
- protected void DropDownList6_SelectedIndexChanged(object sender, EventArgs e)
- DropDownList1.Enabled = true;
- CheckBox5.Enabled = true;
- oldr = fc.SelectFilterType(DropDownList6.SelectedItem.Value, 0, null );
- DropDownList1.DataSource = oldr[0];
- DropDownList1.DataValueField = DropDownList6.SelectedItem.Value;
- DropDownList1.DataBind();
- dropbox to choose the second type
- protected void DropDownList7_SelectedIndexChanged(object sender, EventArgs e)
- DropDownList2.Enabled = true;
- CheckBox6.Enabled = true;
- null);
- oldr = fc.SelectFilterType(DropDownList7.SelectedItem.Value, 1, null);
- DropDownList2.DataSource = oldr[1];
- DropDownList2.DataValueField = DropDownList7.SelectedItem.Value;
- DropDownList2.DataBind();
- dropbox to choose the first value
- protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)//first ddl
- {
- if (DropDownList2.Enabled == true || CheckBox6.Checked == true)
- {
- oldr = fc.SelectFilterValue(DropDownList1.SelectedValue, 0);
- DropDownList2.DataSource = oldr[1];
- }
- }
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Data;
- using System.Data.OleDb;
- /// <summary>
- /// Summary description for Controller
- /// </summary>
- public class FilterController
- {
- public string filterType;
- public int listIndex;
- public string filterValue;
- public FilterTypeValue[] filterTypeList = new FilterTypeValue[4];
- public DatabaseClass dbClass;
- public FilterController()
- {
- }
- public FilterController(string filterType, int listIndex, string filterValue)
- {
- //
- // TODO: Add constructor logic here
- //
- this.filterType = filterType;
- this.filterValue = filterValue;
- this.listIndex = listIndex;
- //filterTypeList[listIndex] = new FilterTypeValue(filterType, filterValue);
- }
- public OleDbDataReader[] SelectFilterType(string filterType, int listIndex, string filterValue)
- {
- filterTypeList[listIndex] = new FilterTypeValue(filterType, filterValue);
- dbClass = new DatabaseClass(filterTypeList,listIndex);
- return dbClass.FilterData();
- }
- public OleDbDataReader[] SelectFilterValue(string filterValue, int listIndex)
- {
- filterTypeList[listIndex].Value = filterValue;
- if(this.listIndex < 3)
- dbClass = new DatabaseClass((FilterTypeValue[])filterTypeList.Clone(), listIndex + 1);
- return dbClass.FilterData();
- }
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- /// <summary>
- /// Summary description for Class1
- /// </summary>
- public class FilterTypeValue
- {
- public string filterType;
- public string filterValue;
- public object Clone()
- {
- FilterTypeValue p = new FilterTypeValue(filterType,filterValue);
- return p;
- }
- public FilterTypeValue(string filterType, string filterValue)
- {
- //
- // TODO: Add constructor logic here
- //
- this.filterType = filterType;
- this.filterValue = filterValue;
- }
- public string FType
- {
- get
- {
- return filterType;
- }
- set
- {
- filterType = value;
- }
- }
- public string Value
- {
- get
- {
- return filterValue;
- }
- set
- {
- filterValue = value;
- }
- }
- }
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Data.OleDb;
- /// <summary>
- /// Summary description for DatabaseClass
- /// </summary>
- public class DatabaseClass :HttpApplication
- {
- public int connectionNumber;
- public OleDbConnection oLDConnection;
- 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";
- public OleDbCommand cmd;
- public OleDbDataReader [] oldr = new OleDbDataReader[4];
- public string[] t = new string[5];
- public string[] f = new string[4];
- FilterTypeValue[] filterTypeList = new FilterTypeValue[4];
- public DatabaseClass(FilterTypeValue[] filterTypeList, int connectionNumber)
- {
- //
- // TODO: Add constructor logic here
- //
- this.connectionNumber = connectionNumber;
- this.filterTypeList = filterTypeList;
- }
- public OleDbDataReader[] FilterData()
- {
- switch (connectionNumber)
- {
- case 0: Connection1();
- break;
- case 1: Connection2();
- break;
- case 2: Connection3();
- break;
- case 3: Connection4();
- break;
- default: Connection1();
- break;
- }
- return oldr;
- }