Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
i got this error in my code which is red here this error is generate from last 3 days i can't understand wt happen plz help me.

<script runat="server">
    
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void BtnViewDetails_Click(object sender, EventArgs e)
    {
        //  get the gridviewrow from the sender so we can get the datakey we need
        Button btnDetails = sender as Button;
        GridViewRow row = (GridViewRow)btnDetails.NamingContainer;
        
        //  extract the customerid from the row whose details button originated the postback.
        //  grab the customerid and feed it to the customer details datasource
        //  finally, rebind the detailview
        this.sqldsCustomerDetails.SelectParameters.Clear();
 [B]       this.sqldsCustomerDetails.SelectParameters.Add("ID", Convert.ToString(this.gvCustomers.DataKeys[row.RowIndex].Value));[/B]
        this.dvCustomerDetail.DataSource = this.sqldsCustomerDetails;
        this.dvCustomerDetail.DataBind();

        //  update the contents in the detail panel
        this.updPnlCustomerDetail.Update();
        //  show the modal popup
        this.mdlPopup.Show();
    }   
    
    </script>

Recommended Answers

All 4 Replies

Try to put value of string type.

this.sqldsCustomerDetails.SelectParameters.Add("ID","value");

now its giving me error on next line "Conversion failed when converting the nvarchar value 'value' to data type int."

this.dvCustomerDetail.DataBind();

on this line when data is bind

Put numeric value.

this.sqldsCustomerDetails.SelectParameters.Add("ID","10");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.