locked
Specified argument was out of the range of valid values. Parameter name: index RRS feed

  • Question

  • User-347949850 posted

    Hi,

    I need some help here regarding my C# ASP.net project.  

    i wish to retrieve the data values from the textbox in each Table Cell.

    The problem that I face is that when i click on the BUTTON to retrieve the information, it show me an error 
    (Specified argument was out of the range of valid values. Parameter name: index)

     The table show above is created dynamically which means when I click 1 time on the ORDER button, 1 new row will be created.

    There are a TextBox in each cell.

    protected void Button9_Click(object sender, EventArgs e)
            {
    
    string retrieveTextBoxString = "";
    int colsCount = 5;
    Table table = (Table)Page.FindControl("myTable");
    for(int i=0; i<= 5; i++)
            {
                for (int j = 0; j < colsCount; j++)
                {
    TextBox tb = (TextBox)table.Rows[i].Cells[j].FindControl("TextBoxRow_" + i + "Col_" + j); //Error SHOWED Here
    retrieveTextBoxString = Request.Form["TextBoxRow_" + i + "Col_" + j];
                }
    
    ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('" + retrieveTextBoxString + "')", true);
    
            }

    I hope you all can help me solve this problem.

    Thanksyou..

    Sunday, May 12, 2013 11:13 AM

Answers

  • User-1716253493 posted

    try

    TextBox tb = (TextBox)table.FindControl("TextBoxRow_" + i.ToString() + "Col_" + j.ToString());

    then

    if (tb!=null)
    {
    
    }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 13, 2013 2:39 AM

All replies

  • User-1716253493 posted
    use for ( int i= 0 ; i< 5 ; i++) instead for ( int i= 0 ; i<= 5 ; i++) or use for ( int i= 0 ; i< table.Rows.Count ; i++)
    Sunday, May 12, 2013 11:27 AM
  • User-347949850 posted

    Hi, 

    I tried to change to   ( int i= 0 ; i< 5 ; i++), the problem still occur to be same.

    Is the problem related to post back issue? Cause everything I click on the button, the table will be recreate all over again but the values can still be retain.

    But when i wan specifically take values from each cell, they dont allow me to take and show that error stated. 

    Sunday, May 12, 2013 11:32 AM
  • User-1716253493 posted
    create the table inside if (!ispostback)
    Sunday, May 12, 2013 11:37 AM
  • User-347949850 posted

    create the table inside if (!ispostback)

    if i dint not create inside if (!ispostback), when i created new row, the UNIQUE ID for each TextBox in each Cell will not be able to retrieve?
     

    Sunday, May 12, 2013 1:31 PM
  • User-1910946339 posted

    What are the values of i and j when you get the error?  How many rows and columns are there in the table at the time the statement is executed?

    Monday, May 13, 2013 2:25 AM
  • User-1716253493 posted

    try

    TextBox tb = (TextBox)table.FindControl("TextBoxRow_" + i.ToString() + "Col_" + j.ToString());

    then

    if (tb!=null)
    {
    
    }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 13, 2013 2:39 AM