Click here to Skip to main content
15,567,615 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my ASP code:

<form id="form1"  runat="server">
   <input type="submit"  runat="server"  önserverclick = "Checkout" />
   <br />
   <asp:Label runat="server" id="oop">

This is my C# code:

public void Checkout (object sender, EventArgs e)
       string[] super = {"Bill" , "Dhoni" , "Jobs"};

       for (int i = 0; i < super.Length; i++)
           oop.Text = super[i].ToString();


When I debug the program I only get Jobs as the output but not all the elements.

Please help me out with this.
Thank you.
Updated 11-Apr-12 6:22am
[no name] 11-Apr-12 11:25am    
It's because you are only setting the text to one element at a time. The last element is the one you see. What is it that you really want to have happen?
Sergey Alexandrovich Kryukov 11-Apr-12 13:03pm    
You should post some of your comments like that as a solution. In this case, it could be the best one. My 5.
[no name] 11-Apr-12 18:32pm    
Probably should. Mark and I were typing at the same time I think. Besides that, the solution makes the textbox text "BillDhoniJobs" which may or may not be what the OP wanted hence my asking him what he really wanted.

The code is functioning correctly. You are overwritting oop.Text each time so it will have value of the last item in your array.
oop.Text = super[i].ToString(); 

If you want it to contain all values then do this
oop.Text += super[i].ToString();
Share this answer
VJ Reddy 11-Apr-12 11:27am    
Lakamraju Raghuram 11-Apr-12 11:32am    
+5I want to post the same
Sipherz 11-Apr-12 11:35am    
Superb u rock!!!!
thank you
try this oop.Text = oop.Text.ToString() + super[i].ToString();
Share this answer
[no name] 11-Apr-12 11:47am    
Ridiculous. Strings don't need ToString() and += is more readable.
Sergey Alexandrovich Kryukov 11-Apr-12 13:05pm    
Aha, you convert string to string. I can imagine how the last of your code looks like. I would advise you to refrain from giving solution until you get comfortable in programming yourself.

Good luck.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900