1 Replies - 9094 Views - Last Post: 19 November 2010 - 11:16 PM Rate Topic: -----

#1 Guest_erum*


Reputation:

how to get valus in dynamic added textbox

Posted 19 November 2010 - 10:00 PM

i have bit tricky kind or problem. i need to get values of each textbox in loop with different names,i have three row (name,telephone,email)and off course three textbox ,can any one help how to get in loop ,i need to insert them in database .the main problem is that values are getiing one by one in loop where i get textbox in for each loop .please get back to me if need further description of problem or u can say that i need to insert multiple columns in database with just single insert query



here is the code

            Dim arr() As String
            Dim record As Int32
            record = 0
            For Each div As System.Web.UI.Control In plholder.Controls
               
                If div.[GetType]().Name = "HtmlGenericControl" Then
                    Dim hml As HtmlGenericControl = DirectCast(div, HtmlGenericControl)


                    Dim str12 As String
                    str12 = hml.TagName
                    str12 = hml.ID

                    For Each table As System.Web.UI.Control In div.Controls

                        If table.[GetType]().Name = "HtmlTable" Then

                            Dim htab As HtmlTable = DirectCast(table, HtmlTable)

                            Dim str13 As String
                            str13 = htab.TagName
                            str13 = htab.ID

                            For Each row As System.Web.UI.Control In table.Controls

                                Dim hrow As HtmlTableRow = DirectCast(row, HtmlTableRow)

                                Dim str14 As String
                                str14 = hrow.TagName
                                str14 = hrow.ID



                                For Each cell As System.Web.UI.Control In row.Controls

                                    Dim hcell As HtmlTableCell = DirectCast(cell, HtmlTableCell)
                                    Dim str15 As String
                                    str15 = hcell.TagName
                                    str15 = hcell.ID

                                    For Each textbox As System.Web.UI.Control In cell.Controls

                                        If textbox.GetType Is GetType(WebControls.TextBox) Then


                                            Dim tbox As TextBox = CType(textbox, System.Web.UI.Control)
                                            Dim str16, str17 As String
                                            str16 = tbox.TextMode
                                            str16 = tbox.ID
                                            str17 = tbox.Text

                                            If tbox.Text <> String.Empty Then
                                                arr(record) = str17
                                                record = record + 1
                                                MsgBox(arr(record))
                                            End If
                                        End If
                                    Next 'textbox
                                Next 'cell
                            Next 'row


                        End If
                    Next 'table

                   
                End If
            Next 'div


This post has been edited by Martyr2: 19 November 2010 - 11:05 PM
Reason for edit:: Please use code tags in the future, thanks!


Is This A Good Question/Topic? 0

Replies To: how to get valus in dynamic added textbox

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4313
  • View blog
  • Posts: 12,090
  • Joined: 18-April 07

Re: how to get valus in dynamic added textbox

Posted 19 November 2010 - 11:16 PM

After your loop has loaded all the textbox data into "arr" you now have an array of strings. You can do four things here depending on how you need to format them in the string.

1) You can use each subscript of the array one by one to build the query.
2) You can use a method like String.Join to join the pieces of the array into a single string.
3) You can use a method like String.Format and provide it the query string with place holders and then pass in the array of strings and it will fill in the pieces.
4) You can create a database command object and loop through the array adding each string to the Parameters collection. When done, you can then execute the query using that command object (look up the Parameters collection under the various command objects like SqlCommand.

Each method works depending on what kind of query you want to build and the design of your system. I suggest you look up String.Join, String.Format, and SqlCommand.Parameters on MSDN and see how each work and how you can use them with your array. String.Join and String.Format can take arrays as parameters and the Parameters collection may require you to loop through "arr".

Hope this helps! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1