473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to display in a form the next object of a collection?

I have a list of objects produced.
after click on next I want to display the next product in the form

in my asp page I have the following form:

Expand|Select|Wrap|Line Numbers
  1. <form id="formNF" runat="server">
  2.  
  3.     <asp:TextBox ID="txtRef" runat="server"></asp:TextBox>
  4.     <asp:TextBox ID="txtArticle" runat="server"></asp:TextBox>
  5.     <asp:TextBox ID="txtQauntity" runat="server"></asp:TextBox>
  6.  
  7.  
  8.     <asp:Button ID="ButtonNext" runat="server" Text="Next product" OnClick="ButtonNext_Click"/>
  9.     </form>
In my code-behind:

Expand|Select|Wrap|Line Numbers
  1.  private int i; 
  2.     protected void ButtonNext_Click(object sender, EventArgs e) { 
  3.          int nbrproducts = command.getListeproducts().Count; 
  4.          i++; 
  5.          for(i=0;i<nbrproducts;) { 
  6.            mdeTxtRef.Text = command.getListeproducts()[i].Ref; 
  7.            mdeTxtQte.Text = command.getListeproducts()[i].Qte; 
  8.          } 
  9.     } 
But it seems as ASP doesn't like this. Have u got an idea? thk u.
Jun 8 '10 #1
2 1165
Frinavale
9,735 Expert Mod 8TB
Store "i" into Session, or ViewState, or ControlState so that the page can retrieve what the last index was that the user was viewing.

For example:
Expand|Select|Wrap|Line Numbers
  1. private int i;
  2.  
  3. protected void Page_Load(object sender, EventArgs e){
  4.   if(IsPostBack == true){
  5.     i = (int)ViewState["productIndex"];
  6.   }else{
  7.     i = 0;
  8.   }
  9. }
  10.  
  11. void Page_PreRender(object sender, EventArgs e){
  12.   ViewState["productIndex"] = i;
  13. }
  14.  
  15. protected void ButtonNext_Click(object sender, EventArgs e) { 
  16.   int nbrproducts = command.getListeproducts().Count; 
  17.   i++; 
  18.   //not sure why you're looping at this point...
  19.   //you know the index..just retrieve the item.
  20.   //for(i=0;i<nbrproducts;) { 
  21.  
  22.   if(i<getListeproducts.Length()){
  23.     //not sure what command is either....
  24.     mdeTxtRef.Text = command.getListeproducts()[i].Ref; 
  25.     mdeTxtQte.Text = command.getListeproducts()[i].Qte; 
  26.   }
  27.   //} 
  28. }
Jun 8 '10 #2
Thank you for this answer, I stored "i" in textbox.
but your solution seem better, I will try with viewstate.
thanks.
Jun 8 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: m. pollack. | last post by:
Hi all, Is there any information to be had about the "Object Collection Editor" that appears when you click on a collection property in the PropertyGrid control? I have a class that maintains a...
0
by: ron | last post by:
Hi, I currently have a jagged array as such. int myJArray = new ; In my constructor i initialize the array of arrays like such. for(int i=0; i<21; i++) { myJArray = new int;
9
by: Alfred Taylor | last post by:
I'm testing the waters of n-tier development and I ran into a scenario that I'm not sure what the best solution would be. I have a Company object which contains a collection of contacts retrieved...
1
by: Weston Weems | last post by:
I've got a collection of objects say fruit. and fruit has a fairly decent heirachial structure not just flat props. I've got my repeater to bind to my fruit collection just fine, but what I want...
3
by: Nak | last post by:
Hi there, I am trying to make a collection that will work in the "Object collection editor" dialog. I have implimeneted ICollection, IList and IEnumerable and now I have an "unnamed"...
0
by: Don | last post by:
I've created a custom class that inherits from System.ComponentModel.Component. Is it possible to get the Windows Form Designer generated code section to automatically add a component of this...
0
by: a | last post by:
Q. Unable to get a Profile custom (object) collection to bind to GridView,etc (IList objects)? This is my first custom object so I may be doing something rather simple, wrong, or it may be...
2
by: Torsten Z | last post by:
Hi, I have tried several things to passing an array of objects or a Object Collection from .NET to VB6 but I can't get it work. Passing one object works fine, but more than one not. Has anybody...
3
by: timothyriggs | last post by:
Building a CRM in Access 2007 with a MySQL backend. Have several objects defined, one of which is the Customer object, another is the Jobs object. The Customer object has a collection of Jobs...
3
by: gasfusion | last post by:
Hey guys. I'm building an object collection which will be a part of a Data Access Layer i am currently working on. However, i am having some issues iterating through a collection. This is what...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.