Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void AddNewRow()
    {
        int rowIndex = 0;
        GridViewRow gvrow = grvStudentDetails.BottomPagerRow;
        if (ViewState["CurrentTable"] != null)
        {
            DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
            DataRow drCurrentRow = null;
            if (dtCurrentTable.Rows.Count > 0)
            {
                for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                {
                    TextBox TextAmount = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[1].FindControl("txtamount");
                    DropDownList dblmode = (DropDownList)grvStudentDetails.Rows[rowIndex].Cells[5].FindControl("dblmode");
                    TextBox TextBank = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[2].FindControl("txtbank");
                    TextBox TextBranch = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[3].FindControl("txtbranch");
                    TextBox TextCheque = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[3].FindControl("txtcheque");
                    RadioButtonList RBLStatus = (RadioButtonList)grvStudentDetails.Rows[rowIndex].Cells[4].FindControl("rblstatus");
           



                    drCurrentRow = dtCurrentTable.NewRow();
                    drCurrentRow["RowNumber"] = i + 1;


                    dtCurrentTable.Rows[i - 1]["Col1"] = TextAmount.Text;
                    dtCurrentTable.Rows[i - 1]["Col2"] = dblmode.SelectedValue;
                    dtCurrentTable.Rows[i - 1]["Col3"] = TextBank.Text;
                    dtCurrentTable.Rows[i - 1]["Col4"] = TextBranch.Text;
                    dtCurrentTable.Rows[i - 1]["Col5"] = TextCheque.Text;
                    dtCurrentTable.Rows[i - 1]["Col6"] = RBLStatus.SelectedValue;
                   


                    rowIndex++;
                }
                dtCurrentTable.Rows.Add(drCurrentRow);
                ViewState["CurrentTable"] = dtCurrentTable;

                grvStudentDetails.DataSource = dtCurrentTable;
                grvStudentDetails.DataBind();               


                TextBox txn = (TextBox)grvStudentDetails.Rows[rowIndex].Cells[1].FindControl("txtamount");
                txn.Focus();
              
            }
        }

I get "error=Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index".

PLZ help me
Posted
Updated 24-Jun-13 1:19am
v2
Comments
Sruthi Jain 24-Jun-13 11:11am    
Would you please put break point in the code while debugging? This will help you to trace to one line where the error has occured.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900