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. repeater control

repeater control

Scheduled Pinned Locked Moved ASP.NET
databasequestion
10 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

    Hi.. I creatd some dynamic textboxes in repeater control.. Had a button to add textboxes.. and link button to delete the rows from db.. im deleting the rows from repeater based on id in the table...upto this its working fine. But when i click on add button to add more rows and if i want to delete those rows, as they dont have any id in table how do i delete those rows..

    A 1 Reply Last reply
    0
    • T test 09

      Hi.. I creatd some dynamic textboxes in repeater control.. Had a button to add textboxes.. and link button to delete the rows from db.. im deleting the rows from repeater based on id in the table...upto this its working fine. But when i click on add button to add more rows and if i want to delete those rows, as they dont have any id in table how do i delete those rows..

      A Offline
      A Offline
      Arun Jacob
      wrote on last edited by
      #2

      where you are keeping the newly added object?or in other words do u have any persisting DataSource object for repeater?

      Arun Jacob http://codepronet.blogspot.com/

      T 1 Reply Last reply
      0
      • A Arun Jacob

        where you are keeping the newly added object?or in other words do u have any persisting DataSource object for repeater?

        Arun Jacob http://codepronet.blogspot.com/

        T Offline
        T Offline
        test 09
        wrote on last edited by
        #3

        the values in the added text boxes if required they are inserted into db.. But before inserting if i need to delete them how can i...

        A 1 Reply Last reply
        0
        • T test 09

          the values in the added text boxes if required they are inserted into db.. But before inserting if i need to delete them how can i...

          A Offline
          A Offline
          Arun Jacob
          wrote on last edited by
          #4

          test-09 wrote:

          the values in the added text boxes if required they are inserted into db.. But before inserting if i need to delete them how can i...

          when clicking new row button how you are adding rows to repeater?Do u have any persisting object in code behind?Have tried deleting by index of the repeater item?

          Arun Jacob http://codepronet.blogspot.com/

          T 1 Reply Last reply
          0
          • A Arun Jacob

            test-09 wrote:

            the values in the added text boxes if required they are inserted into db.. But before inserting if i need to delete them how can i...

            when clicking new row button how you are adding rows to repeater?Do u have any persisting object in code behind?Have tried deleting by index of the repeater item?

            Arun Jacob http://codepronet.blogspot.com/

            T Offline
            T Offline
            test 09
            wrote on last edited by
            #5

            this is how im adding new row...

            private void adddescription()
            {
            int rowIndex = 0;

                      if (ViewState\["CurrentTable"\] != null)
                      {
                          //DataTable dtCurrentTable = (DataTable)ViewState\["CurrentTable"\];
                          dtDesc = (DataTable)ViewState\["CurrentTable"\];
                          DataRow drCurrentRow = dtDesc.NewRow();
                          if (dtDesc.Rows.Count > 0)
                          {
                              for (int i = 1; i <= dtDesc.Rows.Count; i++)
                              {
                                  //extract the TextBox values
                                  TextBox box1 = (TextBox)Rptdescription.Items\[rowIndex\].FindControl("TextName");
                                  TextBox box2 = (TextBox)Rptdescription.Items\[rowIndex\].FindControl("TextDate");
                                  TextBox box3 = (TextBox)Rptdescription.Items\[rowIndex\].FindControl("TextDescript");
                                  drCurrentRow = dtDesc.NewRow();
                                  drCurrentRow\["RowNumber"\] = i ;
                                  ViewState\["RowNumber"\] = drCurrentRow\["RowNumber"\];
                                  Label1.Text = ViewState\["RowNumber"\].ToString();
                                  dtDesc.Rows\[i - 1\]\["DescriptionName"\] = box1.Text;
                                  dtDesc.Rows\[i - 1\]\["Date"\] = box2.Text;
                                  dtDesc.Rows\[i - 1\]\["Description"\] = box3.Text;
                                  rowIndex++;
                              }
                              dtDesc.Rows.Add(drCurrentRow);
                            //  ViewState\["CurrentTable"\] = dtDesc;
                          }
                          else
                          {
                              dtDesc = (DataTable)ViewState\["CurrentTable"\];
                              // dtDesc = (DataTable)ViewState\["CurrentTable"\];
                              DataRow descRow = dtDesc.NewRow();
                              //  descRow\["ProjectID"\] = dtDesc.Rows.Count + 1;
                              descRow\["DescriptionName"\] = "";
                              descRow\["Date"\] = "";
                              descRow\["Description"\] = "";
                              dtDesc.Rows.Add(descRow);
                            //  ViewState\["CurrentTable"\] = dtDesc;
                          }
                      }
                      Bindrepeater();
            }
            
            A 1 Reply Last reply
            0
            • T test 09

              this is how im adding new row...

              private void adddescription()
              {
              int rowIndex = 0;

                        if (ViewState\["CurrentTable"\] != null)
                        {
                            //DataTable dtCurrentTable = (DataTable)ViewState\["CurrentTable"\];
                            dtDesc = (DataTable)ViewState\["CurrentTable"\];
                            DataRow drCurrentRow = dtDesc.NewRow();
                            if (dtDesc.Rows.Count > 0)
                            {
                                for (int i = 1; i <= dtDesc.Rows.Count; i++)
                                {
                                    //extract the TextBox values
                                    TextBox box1 = (TextBox)Rptdescription.Items\[rowIndex\].FindControl("TextName");
                                    TextBox box2 = (TextBox)Rptdescription.Items\[rowIndex\].FindControl("TextDate");
                                    TextBox box3 = (TextBox)Rptdescription.Items\[rowIndex\].FindControl("TextDescript");
                                    drCurrentRow = dtDesc.NewRow();
                                    drCurrentRow\["RowNumber"\] = i ;
                                    ViewState\["RowNumber"\] = drCurrentRow\["RowNumber"\];
                                    Label1.Text = ViewState\["RowNumber"\].ToString();
                                    dtDesc.Rows\[i - 1\]\["DescriptionName"\] = box1.Text;
                                    dtDesc.Rows\[i - 1\]\["Date"\] = box2.Text;
                                    dtDesc.Rows\[i - 1\]\["Description"\] = box3.Text;
                                    rowIndex++;
                                }
                                dtDesc.Rows.Add(drCurrentRow);
                              //  ViewState\["CurrentTable"\] = dtDesc;
                            }
                            else
                            {
                                dtDesc = (DataTable)ViewState\["CurrentTable"\];
                                // dtDesc = (DataTable)ViewState\["CurrentTable"\];
                                DataRow descRow = dtDesc.NewRow();
                                //  descRow\["ProjectID"\] = dtDesc.Rows.Count + 1;
                                descRow\["DescriptionName"\] = "";
                                descRow\["Date"\] = "";
                                descRow\["Description"\] = "";
                                dtDesc.Rows.Add(descRow);
                              //  ViewState\["CurrentTable"\] = dtDesc;
                            }
                        }
                        Bindrepeater();
              }
              
              A Offline
              A Offline
              Arun Jacob
              wrote on last edited by
              #6

              Okay.Delete button is in the repater.right?then in the delete button click event you'll get the item index and using that item index delete that object from the viewstate and rebind repeater.is that makes sense?

              Arun Jacob http://codepronet.blogspot.com/

              T 1 Reply Last reply
              0
              • A Arun Jacob

                Okay.Delete button is in the repater.right?then in the delete button click event you'll get the item index and using that item index delete that object from the viewstate and rebind repeater.is that makes sense?

                Arun Jacob http://codepronet.blogspot.com/

                T Offline
                T Offline
                test 09
                wrote on last edited by
                #7

                im losing the values in textboxs on postback.... i cant check which row im deleting correctly as the values go on postback...

                int iddelete;
                iddelete = ToInt(e.CommandArgument.ToString());
                if (iddelete!=0)
                {
                //code....
                }
                else
                {

                        int count = e.Item.ItemIndex;
                        
                       // count = Convert.ToInt32(ViewState\["RowNumber"\]);
                       //DataTable dtdelete = (DataTable)ViewState\["CurrentTable"\];
                      //  count = dtdelete.Rows.Count - 1;
                        dtdelete.Rows\[count\].Delete();
                        dtdelete.AcceptChanges();
                        Rptdescription.DataSource = dtdelete;
                        Rptdescription.DataBind();
                
                       }
                
                A 1 Reply Last reply
                0
                • T test 09

                  im losing the values in textboxs on postback.... i cant check which row im deleting correctly as the values go on postback...

                  int iddelete;
                  iddelete = ToInt(e.CommandArgument.ToString());
                  if (iddelete!=0)
                  {
                  //code....
                  }
                  else
                  {

                          int count = e.Item.ItemIndex;
                          
                         // count = Convert.ToInt32(ViewState\["RowNumber"\]);
                         //DataTable dtdelete = (DataTable)ViewState\["CurrentTable"\];
                        //  count = dtdelete.Rows.Count - 1;
                          dtdelete.Rows\[count\].Delete();
                          dtdelete.AcceptChanges();
                          Rptdescription.DataSource = dtdelete;
                          Rptdescription.DataBind();
                  
                         }
                  
                  A Offline
                  A Offline
                  Arun Jacob
                  wrote on last edited by
                  #8

                  test-09 wrote:

                  im losing the values in textboxs on postback...

                  Which values you are loosing?ItemIndex is enough to delete it from ViewState?Is this code working?whats the difficulty you are facing in the above code? If you are saying about entered values in textboxes, then save that values to the persisting object before rebinding the repeater.

                  Arun Jacob http://codepronet.blogspot.com/

                  T 1 Reply Last reply
                  0
                  • A Arun Jacob

                    test-09 wrote:

                    im losing the values in textboxs on postback...

                    Which values you are loosing?ItemIndex is enough to delete it from ViewState?Is this code working?whats the difficulty you are facing in the above code? If you are saying about entered values in textboxes, then save that values to the persisting object before rebinding the repeater.

                    Arun Jacob http://codepronet.blogspot.com/

                    T Offline
                    T Offline
                    test 09
                    wrote on last edited by
                    #9

                    the last row is deleting if i click on delete of any row... what may be problem

                    A 1 Reply Last reply
                    0
                    • T test 09

                      the last row is deleting if i click on delete of any row... what may be problem

                      A Offline
                      A Offline
                      Arindam Tewary
                      wrote on last edited by
                      #10

                      You might have 'hard coded' index of last row. Please check that. This could be the case. :laugh:

                      Thanks, Arindam D Tewary

                      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