0

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>

Edited by __avd: Added [code] tags.

2
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by __avd
0

Try to put value of string type.

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

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.