Mobile Content

Saturday, December 24, 2011

Fetch data store in global.asax file in

Here we use array to store data returning from database in global.asax file.

Que: why we are using global.asax file.
        If we use dropdownlist in page, in every postback dropdownlist get filled dynamically.if list of data is long process increases to reduce the process we are storing data into array in Application Start method in global.asax file when page every postback data get filled from array into dropdownlist instead from database.




SqlConnection con=new SqlConnection("Connectionstring");
SqlCommand cmd=new SqlCommand("select name from test",con);
SqlDataAdapter da=new SqlDataAdapter(cmd);
Dataset ds=new Dataset();
int cnt=ds.Tables[0].Rows.Count;
string st=new string[1000];
for( int i=0; i < cnt ; i++ )

in Default.aspx

<asp:DropDownList Id="DropDownList1" runat="server" />

in Default.aspx.cs

string st=(string[])page.Application["add"];
for(int i=0; i < st.length; i++)


When page is loaded at that time data from database get filled in array.So in every postback in applcation dropdownlist get filled by using array variable.

No comments:

Post a Comment