Current location: Hot Scripts Forums » Programming Languages » ASP.NET » How to store multiple values in a string without overriding the pervious one


How to store multiple values in a string without overriding the pervious one

Reply
  #1 (permalink)  
Old 05-18-04, 06:23 AM
bamboat_3 bamboat_3 is offline
New Member
 
Join Date: May 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
How to store multiple values in a string without overriding the pervious one

Hi Friends,

I am new user of ASP.NET. I’m trying to store the multiple values in a string, but very time it override the pervious value whenever I call the function through a command button.

Please help me out.

Here I also enclosing the sample coding for your reference

<%@Page Language=VB Debug=True %>
<Script runat="server">

Dim WorkExperience as String


Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)


lblMessage.Text = "Press a button !"

WorkExperience +=" Hello !"

End Sub



Sub SubmitBtn_AddValue(Sender as Object, E as EventArgs)



WorkExperience + = "IT Officer"
WorkExperience + = "01,"
WorkExperience + = "2002,"
WorkExperience + = "02,"
WorkExperience + = "2002,"
WorkExperience + = "Hello2,"
WorkExperience + = "+"


lblMessage.Text= WorkExperience

End Sub

</Script>

<html>
<body>
<form runat="server">
<asp:Label
id="lblMessage"
Text=""
runat="server"
/>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<asp:Button
id="butAlone"
text="Add Value"
OnClick="SubmitBtn_AddValue"
runat="server"
/>

<BR>
<BR>
</form>
</body>
</html>

Try to run the above cited code. You will find a button named as "Add Value", if u press this button it will display a dummy value, now I want that if you press this Add Value more than once time then it must display the dummy value respectively.

For Example: Press this button 3 times then it must show the same value 3 times.

Please reply me soon because all my work is halt due to this problem

Looking forward to your reply...

Regards,
Mustafa Bamboat
bamboat_3@hotmail.com
Reply With Quote
  #2 (permalink)  
Old 05-20-04, 12:49 PM
Shane Shane is offline
Coding Addict
 
Join Date: Jun 2003
Location: Maryland, US
Posts: 268
Thanks: 0
Thanked 0 Times in 0 Posts
The problem is that you are not retrieving the value of the label before you append the data to the end of the string.

You overwrite the data every time with the variable you're using, but you're never getting the data that already existed first.
__________________
Shane Bauer
Microsoft Certified Professional (MCP) - ASP.NET
ASP/ASP.net, C#, VB/VB.NET, PHP, Perl, SQL
Reply With Quote
  #3 (permalink)  
Old 05-20-04, 10:34 PM
bamboat_3 bamboat_3 is offline
New Member
 
Join Date: May 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Reply to post 'How to store multiple values in a string without overriding

Dear Shane,
I solved out this problem by using the ViewState Command lets try this in the code.
Something looks like that:

If Not Isnothing(ViewState("SavedWorkExperience")) Then
WorkExperience = ViewState("SavedWorkExperience")
End If

WorkExperience = "IT Office"
WorkExperience += "Hello"
WorkExperience += " how r"
WorkExperience += "U !!!"

ViewState("SavedWorkExperience") = WorkExperience

This is working fine and it solved out my problem what I was facing
Please avoid the spelling mistakes
Thank you.

Quote:
Originally Posted by Shane
The problem is that you are not retrieving the value of the label before you append the data to the end of the string.

You overwrite the data every time with the variable you're using, but you're never getting the data that already existed first.
Reply With Quote
  #4 (permalink)  
Old 08-26-04, 09:08 AM
GO4TF4CE's Avatar
GO4TF4CE GO4TF4CE is offline
Wannabe Coder
 
Join Date: Apr 2004
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Talking

just incase anyone finds this useful there is a string builder function which is pretty handy when doing sql commands.

Dim TempSQL as New StringBuilder()
TempSQL.append("1,")
TempSQL.append("2,")
TempSQL.append("3")

and just use TempSQL.tostring() to get the whole string which would be 1,2,3 in this case.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Putting multiple values from list into one field rush989 PHP 1 02-04-04 04:47 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
multiple values in one field smallbeer PHP 6 12-17-03 04:45 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM
store values superman PHP 1 07-06-03 06:17 AM


All times are GMT -5. The time now is 02:54 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.