Click here to Skip to main content
15,908,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
error message

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



C++
protected void ParamGV_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
        GridView gv = (GridView)(e.CommandSource);
        //string s = gv.DataKeys[row.RowIndex][0].ToString();
        int i = Convert.ToInt32(e.CommandArgument);
        GridViewRow Childrow = gv.Rows[i];
        //HeadNameDdl.SelectedValue = Server.HtmlDecode(Childrow.Cells[1].Text).Trim();
        //ViewState["ParameterId"] = Server.HtmlDecode(Childrow.Cells[2].Text).Trim();
        //ParameterNametxt.Text = Server.HtmlDecode(Childrow.Cells[3].Text).Trim();
    }


i have nested grid view, in inner grid Edit i.e
XML
<asp:CommandField SelectText="EDIT" ShowSelectButton="True" ItemStyle-Width="15"
                                                           HeaderText="EDIT">
                                                           <ItemStyle Width="15px" />
                                                       </asp:CommandField>




command filed

On pressing Edit it firing
C++
ParamGV_RowCommand

event but am getting above error , i observered gv.row.count is zero why
Posted

:thumbsdown:

i think there is not found the equalent records. So, record count is Zero.

so, you check the condition:rose:


:thumbsup:
 
Share this answer
 
try the following code....
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.Header && e.Row.RowType
!= DataControlRowType.Footer && e.Row.RowType !=
DataControlRowType.Pager)
{
LinkButton lblTagLink =new LinkButton();
lblTagLink = (LinkButton)e.Row.FindControl("btnAddTags");
lblTagLink.CommandArgument= e.Row.RowIndex.ToString();
}
}


Then get the row index in

protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{

int RowIndex_ = int.Parse(e.CommandArgument.ToString());
Label lblMediaID_ =
(Label)GridView1.Rows[RowIndex_].FindControl("lblMedia_ID");

}
 
Share this answer
 

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