ICollection List and IList

Discussion in 'ASP .Net' started by =?Utf-8?B?TG9nZ2Vy?=, Jul 13, 2007.

  1. 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!!
     
    =?Utf-8?B?TG9nZ2Vy?=, Jul 13, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?TG9nZ2Vy?=

    nahid Guest

    On Jul 13, 10:46 pm, Logger <> wrote:
    > 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
     
    nahid, Jul 13, 2007
    #2
    1. Advertising

  3. 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" wrote:

    > On Jul 13, 10:46 pm, Logger <> wrote:
    > > 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
    >
    >
     
    =?Utf-8?B?TG9nZ2Vy?=, Jul 13, 2007
    #3
  4. =?Utf-8?B?TG9nZ2Vy?=

    nahid Guest

    On Jul 14, 1:16 am, Logger <> wrote:
    > 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" wrote:
    > > On Jul 13, 10:46 pm, Logger <> wrote:
    > > > 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- Hide quoted text -

    >
    > - 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
     
    nahid, Jul 13, 2007
    #4
  5. =?Utf-8?B?TG9nZ2Vy?=

    mark4asp Guest

    On Fri, 13 Jul 2007 09:46:06 -0700, Logger
    <> wrote:

    >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.
     
    mark4asp, Jul 14, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Janus Knudsen

    method type ICollection returns Dataview

    Janus Knudsen, Jul 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,868
    Natty Gur
    Jul 6, 2004
  2. HP
    Replies:
    1
    Views:
    1,628
    =?Utf-8?B?RG90TmV0SmVyb21l?=
    Feb 26, 2005
  3. Pinkesh
    Replies:
    0
    Views:
    346
    Pinkesh
    Jan 12, 2007
  4. Polaris431
    Replies:
    2
    Views:
    496
    Chris Dollin
    Nov 9, 2006
  5. Logger

    Icollection List and Ilist

    Logger, Jul 13, 2007, in forum: ASP General
    Replies:
    0
    Views:
    120
    Logger
    Jul 13, 2007
Loading...

Share This Page