SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Please solve this ERROR

    Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index

    Source Error:


    Line 244: {
    Line 245: // Retreive the Employee ID
    Line 246: int RollNo = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
    Line 247: // Pass the value of the selected RollNo to the Delete //Method.
    Line 248: DeleteStudent(RollNo);


    This is the actual code

    protected void Button2_Click(object sender, EventArgs e)
    {
    // Looping through all the rows in the GridView
    //for (int i = 0; i <= GridView1.Rows.Count; i++)
    //{
    //GridViewRow row = GridView1.Rows[i];
    foreach (GridViewRow row in GridView1.Rows)
    {
    CheckBox checkbox1 = (CheckBox)row.FindControl("CheckBox1");

    //Check if the checkbox is checked.
    //value in the HtmlInputCheckBox's Value property is set as the //value of the delete method's parameter.
    if (checkbox1.Checked)
    {
    // Retreive the Employee ID
    int RollNo = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
    // Pass the value of the selected RollNo to the Delete //Method.
    DeleteStudent(RollNo);
    BindGrid();


    }
    }
    }

  2. #2
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check whether your GridView has the DataKeyName property set. Maybe your DataKeys collection is empty?

  3. #3
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reply for ur message

    Hi!

    I checked the property. It has been set to 'RollNo' which is primary key. Even though it is not working


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •