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

后端 未结 2 2007
死守一世寂寞
死守一世寂寞 2021-01-27 10:07

When i am click on update button i got this error my update click event

protected void btnUpdate_Click(object sender, CommandEventArgs e)
{
    int idx = Conve         


        
相关标签:
2条回答
  • 2021-01-27 10:53

    How many rows do you have?

    Try this:

    int idx = Convert.ToInt32(e.CommandArgument);
    
    if (idx < gvResTasks.Rows.Count)
    {
        GridViewRow gr = gvResTasks.Rows[idx];
    }
    

    Also, can you provide the btnUpdate ASPX code?

    0 讨论(0)
  • 2021-01-27 11:05

    No need to use e.CommandArgument to find the GridViewRow. Just do this

    GridViewRow gr = ((Button)sender).NamingContainer as GridViewRow;
    
    0 讨论(0)
提交回复
热议问题