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. dynamic textbox in repeater

dynamic textbox in repeater

Scheduled Pinned Locked Moved ASP.NET
database
3 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.
  • T Offline
    T Offline
    test 09
    wrote on last edited by
    #1

    string text1 = "";
    string text2 = "";

    private void insertfiles()
    {

        foreach (RepeaterItem item in Rptdescription.Items)
        {
            TextBox txt1 = (TextBox)item.FindControl("TextBox1");
            TextBox txt2 = (TextBox)item.FindControl("TextBox3");
            text1 += txt1.Text + "|";
            text2 += txt2.Text + "|";
       }
                    
        foreach (string split2 in text2.Split('|'))
        {
            stringList.Add(split2 + "<br/>");
            SqlConnection SqlCnn = new SqlConnection(ConfigurationManager.AppSettings\["ConnectionString"\]);
            SqlCommand SqlCmd = new SqlCommand();
            SqlCmd.Connection = SqlCnn;
            SqlCnn.Open();
            SqlCmd.CommandText = "insert into test(test,id) values(@test,1)";
            SqlParameter DataBaseID = new SqlParameter("@test", SqlDbType.NVarChar, 50);
            DataBaseID.Value = stringList.Add(split2);
            SqlCmd.Parameters.Add(DataBaseID);
           
            SqlCmd.ExecuteNonQuery();
            SqlCnn.Close();
            Bindrepeater();
        }
    

    //ignore syntax errors

    This is how im inserting values in textbox into db.. but im having two textboxes how i need to insert both values at a time.. into db... thank you..

    N T 2 Replies Last reply
    0
    • T test 09

      string text1 = "";
      string text2 = "";

      private void insertfiles()
      {

          foreach (RepeaterItem item in Rptdescription.Items)
          {
              TextBox txt1 = (TextBox)item.FindControl("TextBox1");
              TextBox txt2 = (TextBox)item.FindControl("TextBox3");
              text1 += txt1.Text + "|";
              text2 += txt2.Text + "|";
         }
                      
          foreach (string split2 in text2.Split('|'))
          {
              stringList.Add(split2 + "<br/>");
              SqlConnection SqlCnn = new SqlConnection(ConfigurationManager.AppSettings\["ConnectionString"\]);
              SqlCommand SqlCmd = new SqlCommand();
              SqlCmd.Connection = SqlCnn;
              SqlCnn.Open();
              SqlCmd.CommandText = "insert into test(test,id) values(@test,1)";
              SqlParameter DataBaseID = new SqlParameter("@test", SqlDbType.NVarChar, 50);
              DataBaseID.Value = stringList.Add(split2);
              SqlCmd.Parameters.Add(DataBaseID);
             
              SqlCmd.ExecuteNonQuery();
              SqlCnn.Close();
              Bindrepeater();
          }
      

      //ignore syntax errors

      This is how im inserting values in textbox into db.. but im having two textboxes how i need to insert both values at a time.. into db... thank you..

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      What do you mean "insert both values at a time"?


      I know the language. I've read a book. - _Madmatt

      1 Reply Last reply
      0
      • T test 09

        string text1 = "";
        string text2 = "";

        private void insertfiles()
        {

            foreach (RepeaterItem item in Rptdescription.Items)
            {
                TextBox txt1 = (TextBox)item.FindControl("TextBox1");
                TextBox txt2 = (TextBox)item.FindControl("TextBox3");
                text1 += txt1.Text + "|";
                text2 += txt2.Text + "|";
           }
                        
            foreach (string split2 in text2.Split('|'))
            {
                stringList.Add(split2 + "<br/>");
                SqlConnection SqlCnn = new SqlConnection(ConfigurationManager.AppSettings\["ConnectionString"\]);
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection = SqlCnn;
                SqlCnn.Open();
                SqlCmd.CommandText = "insert into test(test,id) values(@test,1)";
                SqlParameter DataBaseID = new SqlParameter("@test", SqlDbType.NVarChar, 50);
                DataBaseID.Value = stringList.Add(split2);
                SqlCmd.Parameters.Add(DataBaseID);
               
                SqlCmd.ExecuteNonQuery();
                SqlCnn.Close();
                Bindrepeater();
            }
        

        //ignore syntax errors

        This is how im inserting values in textbox into db.. but im having two textboxes how i need to insert both values at a time.. into db... thank you..

        T Offline
        T Offline
        T M Gray
        wrote on last edited by
        #3

        I am going to assume that you have the same number of each of the two text boxes. First you should change your loop.

        string[] box1values = text1.split('|')
        string[] box3values = text1.split('|')
        for (int i = 0; i < box1values.length; i++)
        {

        }

        Then you can use the index to get the values of both strings.

        SqlCmd.CommandText = "insert into test(test,test2,id) values(@test,@test2,1)";
        SqlParameter test1Param= new SqlParameter("@test", SqlDbType.NVarChar, 50);
        test1Param.Value = box1values[i];
        SqlParameter test2Param = new SqlParameter("@test2", SqlDbType.NVarChar, 50);
        test2param.Value = box3values[i];
        SqlCmd.Parameters.Add(test1Param);
        SqlCmd.Parameters.Add(test2param);

        I wouldn't call the test1 param DataBaseID since it isn't the column named ID.

        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