aspx_beginners thread: Question reguarding loops
Message #1 by mildge@n... on Mon, 10 Feb 2003 06:17:38
|
|
Hello
loop.vb
Public Class loopClass
Inherits System.Web.UI.Page
Protected lblid As System.Web.UI.WebControls.Label
Public sub Page_Load()
Dim i as integer = 1
Do while i <10
i+=1
lblid.Text = i
Loop
End Sub
loop.aspx
<%@ Page Language="VB" Inherits="loopClass" Src="loop.vb" %>
<html>
<body>
<form id="Form" runat="server">
<asp:label ID="lblid" runat="server" />
</form>
</body>
</html>
using the above code i only get the last item in the loop displayed (in
this case 10)
how do loops work in 'codebehind' so that i would display 1 2 3 4 5 6 7 8
9 10
Message #2 by saena h <saena_h@y...> on Sun, 9 Feb 2003 22:15:45 -0800 (PST)
|
|
mildge@n... wrote:Hello
loop.vb
Public Class loopClass
Inherits System.Web.UI.Page
Protected lblid As System.Web.UI.WebControls.Label
Public sub Page_Load()
Dim i as integer = 1
Do while i <10
i+=1
lblid.Text = i
Loop
End Sub
loop.aspx
using the above code i only get the last item in the loop displayed (in
this case 10)
how do loops work in 'codebehind' so that i would display 1 2 3 4 5 6 7 8
9 10
hello
because you have just one label and it can show just one value it is clear that you can see just the last one.so you have to declare
an arry (here with 10 items) or listbox to show all your outputs!
happy programming!
SAENA
---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
Message #3 by "Rod McLeay" <r.mcleay@c...> on Mon, 10 Feb 2003 14:21:01 +0800
|
|
I don't know ASPX well yet but can see the problem.
Each time you assign i to lblid.Text you are overwriting the original
value.
You must concatinate them together, keeping the original value.
lblid.Text =3D lblid.Text + " " + i
I don't know if the shorthand works in VB like
lblid.Text +=3D " " + i
Rod
-----Original Message-----
From: mildge@n... [mailto:mildge@n...]
Sent: Monday, 10 February 2003 2:18 PM
To: aspx_beginners
Subject: [aspx_beginners] Question reguarding loops
Hello
loop.vb
Public Class loopClass
Inherits System.Web.UI.Page
Protected lblid As System.Web.UI.WebControls.Label
=09
Public sub Page_Load()
Dim i as integer =3D 1
Do while i <10
i+=3D1
lblid.Text =3D i
Loop
End Sub
loop.aspx
<%@ Page Language=3D"VB" Inherits=3D"loopClass" Src=3D"loop.vb" %>
<html>
<body>
<form id=3D"Form" runat=3D"server">
<asp:label ID=3D"lblid" runat=3D"server" />
</form>
</body>
</html>
using the above code i only get the last item in the loop displayed (in
this case 10)
how do loops work in 'codebehind' so that i would display 1 2 3 4 5 6 7
8
9 10
|