Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to navigate through business object's dataset?
Message
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01265575
Message ID:
01265681
Vues:
15
This message has been marked as a message which has helped to the initial question of the thread.
>Hi All,
>
>On a web page I have a registered business object (Inherits ABusinessObject).
>
>Several textboxes on the form are binded to the object via BindingSource and BindingMember properties.
>
>When the web page starts the business object calls the GetAllData(). That makes the textboxes display the values from the first row of the dataset. The dataset then is stored in a session variable.
>
>How can I navigate through the dataset using, for example, First, Last, Next and Prev. buttons?
>
>On postbacks I want to restore the dataset from the session variable not from the database and position it on a certain row. So the textboxes would display that row not the first row in the dataset.
>

DataTables don't really have a concept of "current record". For Winforms, there is a CurrencyManager class to help handle this, but it's a little more bare-metal for an ASP.NET web app. What I would do is store the "current" datarow to a property of the page (or the strongly typed entity) and bind to that instead of the DataSet/DataTable. Store the current row # in a viewstate property and increment /decrement it on postback (depending on whether they clicked the Next or Previous button).
        [DefaultValue(0)]
        public int CurrentRecord
        {
            get
            {
                object currentRecord = ViewState["CurrentRecord"];
                if (currentRecord != null)
                    return (int)currentRecord;
                else
                    return 0;
            }
            set
            {
                ViewState["CurrentRecord"] = value;
            }
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            // No real error checking being done, not handling everything...
            DataSet ds = (DataSet)Session["mytable"];
            DataTable table = ds.Tables[0];            
            
            if (this.CurrentRecord < table.Rows.Count)
            {
                this.CurrentRecord++;
                this.CurrentRow = table.Rows[this.CurrentRecord];
            }
        }
There are also other ways of doing all of this, depending on how you're displaying the data. For example, instead of storing all the info from your table in the session, grab just a like of the primary keys and persist it in the Session or Viewstate. Then when they click on Next/previous, run a query where you return one record based on the PK and use the normal binding process. That would actually have the benefit of making updating the table on a save a bit simpler.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform