Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Panel

Panel

Scheduled Pinned Locked Moved ASP.NET
databasedesignhelptutorial
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KhandelwalA
    wrote on last edited by
    #1

    Hiiiii......i m adding n number of text boxes dynamically in a panel. but when i m going to save those values. it gives me error. My code and error is :

    Dim id As Integer = Request.QueryString("ui")
    Dim cmd2 As String = ("Select Specification from DefineSpecification where CategoryID=" + ID.ToString())
    Dim rdr2 As IDataReader = db.ExecuteReader(CommandType.Text, cmd2)
    Dim conn As New SqlConnection
    Dim cmd As New SqlCommand("Select Count(*) from DefineSpecification Where CategoryID=" + ID.ToString(), conn)
    conn.ConnectionString = ConfigurationManager.ConnectionStrings("See2Buy").ConnectionString
    conn.Open()
    Dim count As Int32 = Convert.ToInt32(cmd.ExecuteScalar())
    While rdr2.Read
    Dim lbl = New Label()
    lbl.Width = "140"
    lbl.Text = rdr2.Item("Specification")
    Panel4.Controls.Add(lbl)
    For counter2 As Integer = 0 To count
    Dim txt = New TextBox()
    txt.Width = "140"
    txt.ID = "TextBoxID" + counter2.ToString
    Panel4.Controls.Add(txt)
    Dim txt1 As TextBox = CType(Panel4.FindControl("TextBoxID" + counter2.ToString()), TextBox)
    Dim txt2 = CStr(txt1.Text)
    Dim cmd3 As String = "Insert into Specification(SpecificationHeading,SpecificationDescription)Values('" + lbl.Text + "','" + txt2 + "')"
    Dim dbcmd As DbCommand = db.GetSqlStringCommand(cmd3)
    db.ExecuteNonQuery(dbcmd)
    Next
    End While

    Error is: Multiple controls with the same ID 'TextBoxID0' were found. FindControl requires that controls have unique IDs. pleas guide me

    P H 2 Replies Last reply
    0
    • K KhandelwalA

      Hiiiii......i m adding n number of text boxes dynamically in a panel. but when i m going to save those values. it gives me error. My code and error is :

      Dim id As Integer = Request.QueryString("ui")
      Dim cmd2 As String = ("Select Specification from DefineSpecification where CategoryID=" + ID.ToString())
      Dim rdr2 As IDataReader = db.ExecuteReader(CommandType.Text, cmd2)
      Dim conn As New SqlConnection
      Dim cmd As New SqlCommand("Select Count(*) from DefineSpecification Where CategoryID=" + ID.ToString(), conn)
      conn.ConnectionString = ConfigurationManager.ConnectionStrings("See2Buy").ConnectionString
      conn.Open()
      Dim count As Int32 = Convert.ToInt32(cmd.ExecuteScalar())
      While rdr2.Read
      Dim lbl = New Label()
      lbl.Width = "140"
      lbl.Text = rdr2.Item("Specification")
      Panel4.Controls.Add(lbl)
      For counter2 As Integer = 0 To count
      Dim txt = New TextBox()
      txt.Width = "140"
      txt.ID = "TextBoxID" + counter2.ToString
      Panel4.Controls.Add(txt)
      Dim txt1 As TextBox = CType(Panel4.FindControl("TextBoxID" + counter2.ToString()), TextBox)
      Dim txt2 = CStr(txt1.Text)
      Dim cmd3 As String = "Insert into Specification(SpecificationHeading,SpecificationDescription)Values('" + lbl.Text + "','" + txt2 + "')"
      Dim dbcmd As DbCommand = db.GetSqlStringCommand(cmd3)
      db.ExecuteNonQuery(dbcmd)
      Next
      End While

      Error is: Multiple controls with the same ID 'TextBoxID0' were found. FindControl requires that controls have unique IDs. pleas guide me

      P Offline
      P Offline
      padmanabhan N
      wrote on last edited by
      #2

      in which line are you getting this error....

      Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]

      K 1 Reply Last reply
      0
      • P padmanabhan N

        in which line are you getting this error....

        Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]

        K Offline
        K Offline
        KhandelwalA
        wrote on last edited by
        #3

        in this line Dim txt1 As TextBox = CType(Panel4.FindControl("TextBoxID" + counter2.ToString()), TextBox)

        1 Reply Last reply
        0
        • K KhandelwalA

          Hiiiii......i m adding n number of text boxes dynamically in a panel. but when i m going to save those values. it gives me error. My code and error is :

          Dim id As Integer = Request.QueryString("ui")
          Dim cmd2 As String = ("Select Specification from DefineSpecification where CategoryID=" + ID.ToString())
          Dim rdr2 As IDataReader = db.ExecuteReader(CommandType.Text, cmd2)
          Dim conn As New SqlConnection
          Dim cmd As New SqlCommand("Select Count(*) from DefineSpecification Where CategoryID=" + ID.ToString(), conn)
          conn.ConnectionString = ConfigurationManager.ConnectionStrings("See2Buy").ConnectionString
          conn.Open()
          Dim count As Int32 = Convert.ToInt32(cmd.ExecuteScalar())
          While rdr2.Read
          Dim lbl = New Label()
          lbl.Width = "140"
          lbl.Text = rdr2.Item("Specification")
          Panel4.Controls.Add(lbl)
          For counter2 As Integer = 0 To count
          Dim txt = New TextBox()
          txt.Width = "140"
          txt.ID = "TextBoxID" + counter2.ToString
          Panel4.Controls.Add(txt)
          Dim txt1 As TextBox = CType(Panel4.FindControl("TextBoxID" + counter2.ToString()), TextBox)
          Dim txt2 = CStr(txt1.Text)
          Dim cmd3 As String = "Insert into Specification(SpecificationHeading,SpecificationDescription)Values('" + lbl.Text + "','" + txt2 + "')"
          Dim dbcmd As DbCommand = db.GetSqlStringCommand(cmd3)
          db.ExecuteNonQuery(dbcmd)
          Next
          End While

          Error is: Multiple controls with the same ID 'TextBoxID0' were found. FindControl requires that controls have unique IDs. pleas guide me

          H Offline
          H Offline
          himanshu2561
          wrote on last edited by
          #4

          hi this error is quite obvious because when datareader read second row from database counter2 in your for loop will again have same value. So, declare one counter before while loop and increament that counter in for loop.this will solve your problem

          himanshu

          K 2 Replies Last reply
          0
          • H himanshu2561

            hi this error is quite obvious because when datareader read second row from database counter2 in your for loop will again have same value. So, declare one counter before while loop and increament that counter in for loop.this will solve your problem

            himanshu

            K Offline
            K Offline
            KhandelwalA
            wrote on last edited by
            #5

            thanks bro :)

            1 Reply Last reply
            0
            • H himanshu2561

              hi this error is quite obvious because when datareader read second row from database counter2 in your for loop will again have same value. So, declare one counter before while loop and increament that counter in for loop.this will solve your problem

              himanshu

              K Offline
              K Offline
              KhandelwalA
              wrote on last edited by
              #6

              hiiiii........as u told me to add counter before while...i added and incremented in for loop.........bt still the same error...can u tell me where to use that specifically in that counter

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups