473,473 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

add value to database from dynamically created textbox

90 New Member
I have created only one object for the textbox and that particular textbox is being repeated as many times I want.But if I want to add the values in the database from each and every textbox which have been dynamically created how should I do that? I have uesd dropdown box to get the number of textboxes to be displayed and used panel to display them.
Let me explain with my real time scenario , if customer-A has 2 telephone lines and customer-B has 3 telephone lines then the textbox are displayed as required but how to add these values to DataBase from dynamically created textboxes?
thanx in advance
Dec 18 '07 #1
3 2402
nateraaaa
663 Recognized Expert Contributor
Do the textboxes that you create dynamically contain an id property for each textbox? If not I would recommend that you use a counter variable or some other way to distinguish which textbox is which. Then simply reference the Text property of the textbox and pass that string value to your database as a parameter in a stored procedure.

Nathan
Dec 18 '07 #2
Frinavale
9,735 Recognized Expert Moderator Expert
I have created only one object for the textbox and that particular textbox is being repeated as many times I want.But if I want to add the values in the database from each and every textbox which have been dynamically created how should I do that? I have uesd dropdown box to get the number of textboxes to be displayed and used panel to display them.
Let me explain with my real time scenario , if customer-A has 2 telephone lines and customer-B has 3 telephone lines then the textbox are displayed as required but how to add these values to DataBase from dynamically created textboxes?
thanx in advance
How are you dynamically displaying the textboxes?
Dec 18 '07 #3
Frinavale
9,735 Recognized Expert Moderator Expert
I have an example for you:

Expand|Select|Wrap|Line Numbers
  1. Private textBoxArr(6) As TextBox
  2.  
  3. Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
  4.     'This event happens before any controls are initialized by ASP.NET
  5.     'The ViewState for objects has not been loaded.
  6.     'After this event happens, the ViewState is loaded for each control and the object's properties are filled with the values submitted.
  7.  
  8.     'Creating the TextBox Objects that are dynamically shown in the web page
  9.     'according to the number selected from a DropDownList
  10.         For x As Integer = 0 To textBoxArr.Length - 1
  11.             textBoxArr(x) = New TextBox
  12.             textBoxArr(x).ID = "myTextBox" + x.ToString
  13.             textBoxArr(x).Visible = False 'Initializing the TextBox so that it is not rendered in the browser 
  14.             Pnl_TextBoxes.Controls.Add(textBoxArr(x)) 'Adding the TextBox to the Panel that holds the text boxes.
  15.         Next
  16.  
  17. End Sub
  18.  
  19. Protected Sub numTextBoxes_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles numTextBoxes.SelectedIndexChanged
  20.         For x As Integer = 0 To numTextBoxes.SelectedValue - 1
  21.             textBoxArr(x).Visible = True 'Setting the TextBox to True
  22.         Next
  23. End Sub
  24.  
  25. Private Sub btnText_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnText.Click
  26.  
  27.         Dim str As New StringBuilder
  28.  
  29.         For i As Integer = 0 To textBoxArr.Length - 1
  30.             If Not textBoxArr(i) Is Nothing Then
  31.                 str.Append(" " + textBoxArr(i).Text) 'Grabbing the text from the TextBox...remember that at this stage the TextBox's Text property has already been set by ASP.NET according to its ViewState
  32.             End If
  33.         Next
  34.  
  35.     'Showing in a label what was in the TextBoxes
  36.         lbl_message.Text = "message: " + str.ToString
  37.     'Instead of showing these values, you should store them in your database.
  38.     End Sub
  39.  
Dec 18 '07 #4

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

Similar topics

2
by: utterberg | last post by:
Can anyone help me with this problem? I dynamically creates several textboxes using a placeholder. This works fine. But is there a way for me to loop through theese textboxes and retrive its value...
4
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in...
2
by: Raed Sawalha | last post by:
Hi, This is probably pretty simple but... I am dynamically adding rows to a HtmlTable that contain Textbox controls. (There may be more than one server control/textbox in a given cell) How...
1
by: RC | last post by:
Hi, I 've created a form with serveral Dynamically Created TextBoxes and a static button. After press the button, those values of TextBoxes should be posted back to server. How to get the value...
5
by: \A_Michigan_User\ | last post by:
I'm using asp.net/vb.net/ado.net to create a very simple user interface. (Everything works if I use STATICALLY created textBoxes... but not when I make them DYNAMICALLY.) 1. Execute a SQL...
0
by: Silver Oak | last post by:
I have a DataGrid in which one of the columns is TemplateColumn that was created dynamically using iTemplate. I would like to have multi-row editing capability on the DataGrid. I'm trying to...
1
by: aekta | last post by:
Hello all, How we get The Value of Dynamic generate TextBox in asp.net? i have a web form and in which i want to create textbox dynamically by click on Button ...Now,on another button click I...
2
by: HHAAPPYY | last post by:
Hi I am trying to pass value of the textbox along with another value to the query string. when i am retriving the txtbox value it always shows me null, my senario is like this On my...
0
by: ahmadbaseet | last post by:
Hello all I am new to VB.NET. I am trying to create dynamically objects and giving them the event handles. Something like this Dim NewTab As New TabPage Dim NewTextBox As New TextBox Dim...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.