C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

Button Click


Posted Date: 07 Nov 2009      Posted By: sirisha      Member Level: Silver     Points: 1   Responses: 3



Hello Everybody.
I am doing a windows appln in vb.net.
I have a button in my form. When i click the button, textboxes are added dynamically to the form. For 1st click 4 textboxes are added. When clicked again, again the textboxes are added once again...Now i need to save the data from the textboxes to database. Pls anyone help me with that. Here is my coding.

Dim value1 As String = ""
Dim value2 As String = ""
Dim value3 As String = ""
Dim value4 As String = ""
Dim i As Integer
For i = 0 To FlowLayoutPanel1.Controls.Count - 1
Select Case FlowLayoutPanel1.Controls(i).Name

Case "TextBox1"
value1 = FlowLayoutPanel1.Controls(i).Text

Case "TextBox2"
value2 = FlowLayoutPanel1.Controls(i).Text

Case "TextBox3"
value3 = FlowLayoutPanel1.Controls(i).Text

Case "TextBox4"
value4 = FlowLayoutPanel1.Controls(i).Text
End Select
Next i
Dim strsql As String
strsql = "insert into stud values ('" & value1 & "','" & value2 & "','" & value3 & "','" & value4 & "')"

Only the text in the first four textboxes is getting aded to the database.What about the others





Responses

Author: Pannalal Sinha    07 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Why are you adding the textboxes on button click.
I think you should add those in the page load, then u need not add them again and again.

After inserting the values in the query, clear the textbox values and use freshly for next button click.

Thanks
Panna



Author: sirisha    08 Nov 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

Thanku for ur reply Sinha
But i dont want to add the textboxes in form load. If the user wants to add 10 records , he wants to add them at a time. He doesnot want to add them one by one every time clicking the save button. Can u help me in that way.



Author: pradeep kumar reddy    09 Nov 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

hi,
yeah you are correct if we write code in page load it creates text boxes each time dynamically. to avoid this we have to create these text boxes in page load in the condition "if(!ispostback)" it means if it already postback means it will not execute again. these will remain as it is.



Post Reply
You must Sign In to post a response.
Next : TimeSetting
Previous : Find and replace in HTML File
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use