Click here to Skip to main content
15,885,669 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using this below code for checking product whether it is available or not but i am getting error as soon as i click on check availability button...the error is as follows

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

I am using the below code:
C#
protected void chckdavail_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow gvr in show_moreDetails.Rows)
        {

            int data1 = Convert.ToInt32(gvr.Cells[7].Text);
            int data2 = Convert.ToInt32(gvr.Cells[8].Text);
            int data3 = Convert.ToInt32(gvr.Cells[9].Text);
            int data4 = Convert.ToInt32(gvr.Cells[10].Text);

            ClsPDF obj1 = new ClsPDF();
            int returnstatus = 0;
            returnstatus = Convert.ToInt32(obj1.productcheck(10, data3, data1, data2,data4));
            if (returnstatus == 1)
            {
                lbldavail.Visible = true;
                lbldavail.Text = "Available";
                lbldavail.ForeColor = System.Drawing.Color.Red;

            }
            else if (returnstatus == 2)
            {
                lbldavail.Text = "Not Available";
                lbldavail.ForeColor = System.Drawing.Color.Green;
                lbldavail.Visible = true;
            }
        }

    }
Posted
Comments
Sandeep Mewara 12-May-12 6:22am    
Which line? Did you used Visual Studio DBUGGER? There are few places where you are using indexes, those are the potential lines. See if the data exists for those indexes.

1 solution

Based on the code it's just guessing where the error would be so try debugging the application and check on what row the problem occurs. It can also be inside the productcheck so remember to step into the method with the debugger.
 
Share this answer
 
Comments
Reza Mansoori 12-May-12 6:49am    
how many column show_moreDetails gridview have?
I think this error is because of Cells[7] or Cells[8] or Cells[9] or Cells[10] . do you know index of cells begins from 0

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