ICollection List and IList

G

Guest

I have two datasets wher I populate a dropdown list on startup, depending on
radio button setting. If rbA then use ds_A, if rbB use ds_B. What is the
best way to store the datasets so I can populate the dropdown list without
having to connect to the db and repopulate the datasets every time? Below is
an example of one of my radio buton _checkedChanged event.

If rb_A.Checked Then
rb_B.Checked = False
ddlhs.Items.Clear()
ddlhs.DataSource = ds_A.Tables(0).DefaultView
ddlhs.DataTextField = "Name"
ddlhs.DataValueField = "Schoolid"
ddlhs.DataBind()
ddlhs.Items.Insert(0, New ListItem)
End If

I’m thinking that I have to use ICollection List and ILIST but I’m not sure
how that would work. With autopostback I keep re-initializing my objects.
Help!!
 
N

nahid

I have two datasets wher I populate a dropdown list on startup, depending on
radio button setting. If rbA then use ds_A, if rbB use ds_B. What is the
best way to store the datasets so I can populate the dropdown list without
having to connect to the db and repopulate the datasets every time? Below is
an example of one of my radio buton _checkedChanged event.

If rb_A.Checked Then
rb_B.Checked = False
ddlhs.Items.Clear()
ddlhs.DataSource = ds_A.Tables(0).DefaultView
ddlhs.DataTextField = "Name"
ddlhs.DataValueField = "Schoolid"
ddlhs.DataBind()
ddlhs.Items.Insert(0, New ListItem)
End If

I'm thinking that I have to use ICollection List and ILIST but I'm not sure
how that would work. With autopostback I keep re-initializing my objects.
Help!!

hi,
you can use viewstate if you have small amount of data..

save to viewstate
viewstate["data"]="your data";

get from viewstate

object g= viewstate["data"] as yourdayatype;

hope help

nahid
http://nahidulkibria.blogspot.com/
http://www.kaz.com.bd
 
G

Guest

I was thinking about that. The datasets can have anywhere between 300 to 500
records each. I was a little concerned about the response time using
viewstate.

nahid said:
I have two datasets wher I populate a dropdown list on startup, depending on
radio button setting. If rbA then use ds_A, if rbB use ds_B. What is the
best way to store the datasets so I can populate the dropdown list without
having to connect to the db and repopulate the datasets every time? Below is
an example of one of my radio buton _checkedChanged event.

If rb_A.Checked Then
rb_B.Checked = False
ddlhs.Items.Clear()
ddlhs.DataSource = ds_A.Tables(0).DefaultView
ddlhs.DataTextField = "Name"
ddlhs.DataValueField = "Schoolid"
ddlhs.DataBind()
ddlhs.Items.Insert(0, New ListItem)
End If

I'm thinking that I have to use ICollection List and ILIST but I'm not sure
how that would work. With autopostback I keep re-initializing my objects.
Help!!

hi,
you can use viewstate if you have small amount of data..

save to viewstate
viewstate["data"]="your data";

get from viewstate

object g= viewstate["data"] as yourdayatype;

hope help

nahid
http://nahidulkibria.blogspot.com/
http://www.kaz.com.bd
 
N

nahid

I was thinking about that. The datasets can have anywhere between 300 to 500
records each. I was a little concerned about the response time using
viewstate.



hi,
you can use viewstate if you have small amount of data..
save to viewstate
viewstate["data"]="your data";
get from viewstate
object g= viewstate["data"] as yourdayatype;
hope help

- Show quoted text -

hmm ,

you can think about Caching
here is a comparison of using cache and no cache
http://aspalliance.com/251

more on http://www.ondotnet.com/pub/a/dotnet/2002/12/30/cachingaspnet.html
about Caching

nahid
http://nahidulkibria.blogspot.com/
http://www.kaz.com.bd
 
M

mark4asp

I have two datasets wher I populate a dropdown list on startup, depending on
radio button setting. If rbA then use ds_A, if rbB use ds_B. What is the
best way to store the datasets so I can populate the dropdown list without
having to connect to the db and repopulate the datasets every time? Below is
an example of one of my radio buton _checkedChanged event.

If rb_A.Checked Then
rb_B.Checked = False
ddlhs.Items.Clear()
ddlhs.DataSource = ds_A.Tables(0).DefaultView
ddlhs.DataTextField = "Name"
ddlhs.DataValueField = "Schoolid"
ddlhs.DataBind()
ddlhs.Items.Insert(0, New ListItem)
End If

I’m thinking that I have to use ICollection List and ILIST but I’m not sure
how that would work. With autopostback I keep re-initializing my objects.
Help!!

Does the data in these datasets vary with each different user? If not
you can store your DataSet in the Cache.

Why don't you use a DataTable to store the data in preference to a
DataSet? A DataTable is faster to load (when using a DataReader) than a
DataSet. (although it needs more coding from you).

When I have pages which display identical data for different users I
prefer to use a generic list ( List<T> ) which is stored as a static
object.

For instance if you had a DropDownList of Schools it may be something
like this.

Class School
{
private int _schoolid = 0;
private string _name = String.Empty;

public School(int schoolid, name)
{
this._schoolid = schoolid;
this._name = name;
}

public Schoolid { get { return _schoolid ; } }
public Name { get { return _name; } }

}

using System.Collections.Generic;
Class Schools
{
public static List<School> list = null;

private Schools() {}

public static LoadSchools()
{
list = DAL.GetSchools();
// database call using GetSchools() uses a DataReader,
// with the Add method of List<T>
// and the School constructor.
}
}

So your code can be something like this:

...
ddlhs.Items.Clear()
ddlhs.DataSource = Schools.list;
ddlhs.DataTextField = "Name";
ddlhs.DataValueField = "Schoolid";
ddlhs.Databind();
...

PS 1: It's not a clever idea to use a variable called Name. Use
SchoolName instead? My aversion to that comes from ASP days when it was
death to you page to call something "Name".

PS 2: The Schools class should be implemented using a 'singleton
pattern'. (Look it up). In the above case you will run LoadSchools()
once, perhaps in Application.OnStart().

Sorry, I don't use VB.NET but you should be able to convert the above
easily.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top